The sign-propagating right shift operator (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.
>>) shifts the binary representation of the first operand to the right by the number of bits specified by the second operand. It discards bits shifted off to the right and preserves the original number’s sign by copying the leftmost bit (the sign bit) into the newly vacated bit positions on the left. The operator supports both Number and BigInt types.
Technical Mechanics: Number Operands
When both operands are standard JavaScript Number values, the operator applies 32-bit integer semantics:
- Type Coercion: The left operand (
a) is converted to a 32-bit signed integer using the ECMAScriptToInt32abstract operation. The right operand (b) is converted to a 32-bit unsigned integer using theToUint32abstract operation. Fractional parts are truncated. Non-numeric values (likeNaN,null, orundefined) are coerced to0. - Modulo Shift Amount: The evaluated right operand is masked to 5 bits (
b & 0x1F). The effective shift amount is alwaysb % 32. Shifting by 32, 64, or 96 bits is functionally identical to shifting by 0 bits. - Sign Extension: JavaScript uses the 32nd bit of the
ToInt32representation as the sign indicator (0for positive,1for negative). If the original number is positive,0s are shifted in from the left. If negative,1s are shifted in from the left, maintaining the two’s complement structure.
Technical Mechanics: BigInt Operands
When both operands are BigInt values, the operator applies arbitrary-precision semantics:
- Arbitrary Precision:
BigIntvalues are not truncated to 32 bits. They conceptually operate on an infinite-length two’s complement binary representation. - Unmasked Shift Amount: The right operand is not masked. A
BigIntcan be shifted by more than 32 bits, and the operation mathematically evaluates toa / (2n ** b)(rounded towards negative infinity). - Sign Extension: The sign is preserved mathematically without relying on a fixed 32nd bit.
Syntax Visualization
Number: Positive Integer Shift When shifting a positive integer, the sign bit is0, so 0s are populated from the left.
1, so 1s are populated from the left.
BigInt shifts process the full magnitude without 32-bit truncation or modulo masking.
Edge Cases and Coercion Behavior
Type Mixing (TypeError)
Mixing Number and BigInt operands is strictly prohibited and throws a TypeError.
ToInt32 conversion for standard numbers, the >> operator strips floating-point decimals before shifting:
Number operands:
Master JavaScript with Deep Grasping Methodology!Learn More





