JavaScript | Bitwise OR Operator
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 | yExample
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.
Desktop





Tablets & Mobile





