Skip to main content
The >>> (unsigned right shift or zero-fill right shift) operator 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 the right and fills the newly vacated bits on the left with zeroes (0). Because it does not preserve the sign bit, the operation always evaluates to a non-negative 32-bit unsigned integer.

Technical Mechanics

  1. Type Coercion: TypeScript (inheriting from JavaScript’s underlying ECMAScript specification) internally converts operand1 into a 32-bit unsigned integer (ToUint32).
  2. Shift Masking: operand2 is converted to an unsigned 32-bit integer and masked using a bitwise AND (operand2 & 0x1F). This restricts the actual shift amount to a value between 0 and 31 bits.
  3. Zero-filling: As bits are shifted to the right, the leftmost bits are populated with 0. This fundamentally alters negative numbers, as their leading 1 (the sign bit in two’s complement representation) is replaced by 0.
  4. Return Type: The result is always returned as a 32-bit unsigned integer, typed as number in TypeScript.
  5. BigInt Incompatibility: >>> is the only bitwise operator in TypeScript/JavaScript that does not support BigInt. Because BigInt represents arbitrary-precision integers without a fixed bit-width, an unsigned right shift is mathematically invalid. Attempting to use >>> with bigint operands throws a compilation error.

Behavior Visualization

Positive Integer Shift: When shifting positive numbers, >>> yields the exact same result as the sign-propagating right shift (>>) because the sign bit is already 0.
Negative Integer Shift: When shifting negative numbers, the 32-bit two’s complement representation is shifted. The leading 1s are replaced with 0s, resulting in a large positive integer.
Float Truncation: If the left operand is a floating-point number, the fractional portion is truncated during the ToUint32 coercion before the shift occurs.
Zero-Shift Coercion: Shifting by 0 bits forces any value into a 32-bit unsigned integer without altering its bit sequence.
BigInt Rejection: Applying >>> to bigint types results in a strict type error.
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More