Favorites

JavaScript | Bitwise OR Operator

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
|
JavaScript Bitwise OperatorThis operator is supported by all modern browsers.
Updated 28th November 2026

The bitwise OR operator (|) sets each bit to 1 where either integer has a 1. It's used to combine flags.

Description

The bitwise OR operator | returns a 32-bit integer with a 1 in each bit position where either operand has a 1. It's used to combine flags. Because it converts to a 32-bit integer, x | 0 truncates decimals, but it breaks for numbers beyond about ±2.1 billion, so Math.trunc() is safer.

Combining flags with | sets every bit that's set in either value, so READ | WRITE creates a value with both permissions. To remove a flag, use & with the inverted flag: perms & ~WRITE. The assignment form, flags |= EXEC, adds a flag in place.

Like other bitwise operators, it converts operands to 32-bit integers. Don't mix it up with ||: | always evaluates both sides and returns a number, while || short-circuits and returns one of the operands.

Properties

Operator
|
Category
Bitwise
Precedence
5 (1 is lowest, 18 is highest)
Associativity
left-to-right

Syntax

x | y

Example

console.log(5 | 3);
const BOLD = 1, ITALIC = 2;
console.log(BOLD | ITALIC);
console.log(7.9 | 0);

Browser Support

The following information will show you the current browser support for the | operator. Hover over a browser icon to see the version that first introduced support for this operator.

This operator is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee