Skip to main content
The | (Bitwise OR) operator performs a logical OR operation on each pair of corresponding bits of its operands. Depending on the operand types, it evaluates them either as 32-bit signed integers (for Number values) or as arbitrary-precision integers (for BigInt values), returning a new value of the matching type where each bit is set to 1 if at least one of the corresponding bits in the operands is 1.

Syntax

Execution Mechanics

  1. Type Evaluation and Coercion:
    • Number Operands: If the operands are standard numbers (or non-BigInt values coercible to numbers), JavaScript passes them through the internal ToInt32 abstract operation.
      • Fractional values are strictly truncated (the decimal portion is discarded).
      • Non-numeric values are coerced to numbers. Values that resolve to NaN, null, or undefined are converted to 0.
      • Numeric values exceeding the 32-bit signed integer limit wrap around.
    • BigInt Operands: If both operands are BigInt values, they are evaluated as arbitrary-precision integers using two’s complement representation. They bypass ToInt32 entirely and are not truncated to 32 bits.
    • Mixed Types: Attempting to apply the operator to a mix of BigInt and Number operands throws a TypeError.
  2. Bitwise Alignment: The JavaScript engine aligns the binary representations of both integers. For Number operands, this is strictly bounded to 32 bits. For BigInt operands, the representation conceptually extends with infinite sign bits to accommodate the magnitude of the values.
  3. Evaluation: A logical OR is applied to each bit position according to the following truth table:
    • 0 | 0 yields 0
    • 0 | 1 yields 1
    • 1 | 0 yields 1
    • 1 | 1 yields 1

Code Visualization

Standard Number Evaluation
BigInt Evaluation
Mixed Type Error
Type Coercion and Truncation (Number only)
Negative Integer Evaluation (Two’s Complement)
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More