Skip to main content

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.

The >>> (unsigned right shift) operator shifts the binary representation of the first operand to the right by the number of bits specified by the second operand, shifting in zeroes from the left. Unlike the sign-propagating right shift (>>), it does not preserve the sign bit, guaranteeing that the evaluated result is always a non-negative 32-bit unsigned integer.
operand >>> shiftAmount

Technical Mechanics

When the JavaScript engine evaluates a >>> operation, it performs the following sequence of internal steps:
  1. Type Coercion: The left operand is converted to a 32-bit integer. For the purposes of this specific operator, it is treated as a 32-bit unsigned integer (Uint32).
  2. Shift Masking: The shiftAmount is converted to a 32-bit integer and masked to 5 bits using a bitwise AND (shiftAmount & 0x1F). This ensures the actual shift amount is always an integer between 0 and 31 inclusive.
  3. Bit Shifting: The bits of the left operand are moved to the right by the calculated shift amount.
  4. Zero-Fill: As bits are shifted to the right, 0 bits are inserted from the far left (the most significant bit position).
  5. Truncation: Any bits shifted past the 0th position (the least significant bit) are permanently discarded.

BigInt Incompatibility

In JavaScript, >>> is the only bitwise operator that does not support BigInt operands. Because BigInt values represent arbitrary-precision integers and lack a fixed bit-width, the concept of filling zeroes from a fixed leftmost boundary does not apply. Attempting to use >>> with a BigInt operand throws a TypeError.
const bigValue = 10n;

console.log(bigValue >>> 1n); 
// TypeError: BigInts have no unsigned right shift, use >> instead

Behavioral Examples

Positive Integers

For positive integers, >>> behaves identically to >> because the sign bit is already 0.
const a = 9; 
// Binary: 00000000000000000000000000001001

const result = a >>> 2; 
// Binary: 00000000000000000000000000000010
// Decimal: 2

Negative Integers

For negative integers, the behavior diverges significantly from >>. Negative numbers are represented in 32-bit two’s complement, meaning their leftmost bit (sign bit) is 1. Because >>> forces zeroes in from the left, the sign bit is overwritten, resulting in a large positive integer.
const b = -9;
// Binary: 11111111111111111111111111110111 (Two's complement of -9)

const result = b >>> 2;
// Binary: 00111111111111111111111111111101
// Decimal: 1073741821

Shift Amount Modulo

Because the right operand is masked to 5 bits, shifting by 32 is equivalent to shifting by 0.
const c = 255;

console.log(c >>> 32); // 255 (32 & 31 = 0)
console.log(c >>> 33); // 127 (33 & 31 = 1)

Non-Integer Coercion

If the left operand is a non-integer, JavaScript truncates the fractional part during the 32-bit integer conversion before applying the shift. If the operand cannot be converted to a number (e.g., NaN, undefined), it is coerced to 0.
console.log(10.99 >>> 1); // 5 (10.99 is coerced to 10, then shifted)
console.log("42" >>> 1);  // 21 (String "42" is coerced to Number 42, then shifted)
console.log(NaN >>> 1);   // 0
Master JavaScript with Deep Grasping Methodology!Learn More