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.
<<= (Left Shift Assignment) operator performs a bitwise left shift on its left operand by the number of bits specified by its right operand, and assigns the resulting value to the left operand.
Syntax
x = x << y
Execution Mechanics
The behavior of the<<= operator depends strictly on the types of its evaluated operands. JavaScript supports bitwise operations on both Number and BigInt types, but mixing the two throws a TypeError.
For Number Operands
When operating on standard JavaScript numbers (or values coerced to numbers), the engine performs the following sequence:
- Type Coercion: Both operands are implicitly coerced to 32-bit integers. The left operand is converted to a 32-bit signed integer (
ToInt32), and the right operand is converted to a 32-bit unsigned integer (ToUint32). - Shift Masking: The right operand is masked with
0x1F(bitwise AND with 31). This applies a modulo 32 operation, ensuring the shift amount is strictly between0and31bits. Shifting by 32 bits or more wraps around. - Bit Manipulation: The 32-bit binary representation of the left operand is shifted to the left by the calculated number of bits.
- Zero-Filling: Vacated bit positions on the right side are filled with zeros (
0). - Truncation: Any bits shifted beyond the 32nd bit boundary on the left are discarded.
- Assignment: The resulting 32-bit signed integer is assigned back to the left operand.
For BigInt Operands
When both operands are BigInt primitives, the 32-bit limitations are bypassed:
- Validation: The engine checks the right operand. If the shift amount is negative, a
RangeErroris thrown. - Bit Manipulation: The left operand is shifted left by the exact, unmasked number of bits specified by the right operand.
- Zero-Filling: Vacated bit positions on the right are filled with zeros (
0). - No Truncation or Masking: The right operand is not masked with
0x1F, and the result is not truncated to 32 bits. The resulting binary representation grows to accommodate the shifted magnitude. - Assignment: The resulting
BigIntis assigned back to the left operand.
Mechanical Examples
Basic Shift (Number)Master JavaScript with Deep Grasping Methodology!Learn More





