> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript Bitwise OR

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

```javascript theme={"dark"}
operand1 | operand2
```

## 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**

```javascript theme={"dark"}
const a = 5;  // Binary: 00000000000000000000000000000101
const b = 3;  // Binary: 00000000000000000000000000000011

console.log(a | b); // Output: 7
// Result Binary:      00000000000000000000000000000111
```

**BigInt Evaluation**

```javascript theme={"dark"}
const bigA = 8589934592n; // 2^33 (Exceeds 32-bit limit)
const bigB = 5n;

// Evaluates with arbitrary precision, no 32-bit truncation
console.log(bigA | bigB); // Output: 8589934597n
```

**Mixed Type Error**

```javascript theme={"dark"}
console.log(5n | 3); 
// Output: TypeError: Cannot mix BigInt and other types, use explicit conversions
```

**Type Coercion and Truncation (`Number` only)**

```javascript theme={"dark"}
// Floating-point truncation
console.log(5.99 | 1.2); // Output: 5
// Step 1: 5.99 is truncated to 5 (0101)
// Step 2: 1.2 is truncated to 1 (0001)
// Step 3: 5 | 1 evaluates to 5 (0101)

// String coercion
console.log("10" | 2); // Output: 10
// Step 1: "10" is coerced to integer 10 (1010)
// Step 2: 2 remains 2 (0010)
// Step 3: 10 | 2 evaluates to 10 (1010)

// NaN / Undefined coercion
console.log(NaN | 4); // Output: 4
// Step 1: NaN is coerced to 0 (0000)
// Step 2: 4 remains 4 (0100)
// Step 3: 0 | 4 evaluates to 4 (0100)
```

**Negative Integer Evaluation (Two's Complement)**

```javascript theme={"dark"}
const c = -5; // Binary: 11111111111111111111111111111011
const d = 2;  // Binary: 00000000000000000000000000000010

console.log(c | d); // Output: -5
// Result Binary:      11111111111111111111111111111011
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor JavaScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
