TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
|= (Bitwise OR assignment) operator evaluates the binary representations of its left and right operands, performs a bitwise OR operation (|), and assigns the computed result to the left operand.
x = x | y, the |= operator evaluates the left-hand expression only once. This semantic distinction is critical when the left operand contains side effects, such as property accessors or increment/decrement operations.
Execution Mechanics
When the JavaScript engine encounters the|= operator, it executes the following sequence based on the operand types:
- Type Resolution: The engine determines the numeric type of the operands. If one operand is a
BigIntand the other is aNumber, the engine throws aTypeError. - Numeric Conversion and Alignment:
- For
Numberoperands: Both operands are implicitly converted to 32-bit signed integers using the internalToInt32abstract operation. Fractional values are truncated (e.g.,5.9becomes5), and non-numeric values are coerced to numbers (or0if coercion results inNaN). The engine aligns their 32-bit two’s complement binary representations. - For
BigIntoperands: The engine does not truncate to 32 bits. It aligns the arbitrary-precision integers using two’s complement representation.
- For
- Bitwise Evaluation: A logical OR is applied to each pair of corresponding bits. The resulting bit is
1if at least one of the corresponding bits in the operands is1. It is0only if both bits are0. - Assignment: The resulting integer (either a 32-bit
Numberor aBigInt) is assigned back to the left operand.
Bitwise OR Truth Table
| Bit A (Left) | Bit B (Right) | Result (A | B) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Code Visualization
Coercion and Type Behavior
Because of the mandatoryToInt32 conversion for standard numbers and the strict type requirements for BigInt, using |= yields specific structural behaviors:
Master JavaScript with Deep Grasping Methodology!Learn More





