Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Right shift assignment (>>=)

The >>= operator shifts bits right while preserving the sign and writes the result back to its left operand. It supports Number and BigInt, with different rules for numeric width and shift counts.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

target >>= shiftCount

target >>= shiftCount reads the target's value, performs the >> shift, and writes the result back to that target. For a simple variable, it behaves like target = target >> shiftCount, but the expression identifying the target is evaluated only once. The entire expression evaluates to the assigned result. The target must allow writing; assigning to a const variable throws a TypeError.

For Number, the left operand is converted to a signed 32-bit integer. The right operand is converted to an unsigned 32-bit integer and then reduced modulo 32: shifting by 33 behaves like shifting by 1. Bits shifted off the right are discarded, and the sign bit is copied into the leftmost positions. Thus, -9 >> 1 produces -5, not -4. This is not a general replacement for division, because conversion to 32 bits can change the value.

For BigInt, there is no conversion to 32 bits and no reduction of the shift count modulo 32. A negative shift count reverses the shift direction. After conversion to numeric values, both operands must have the same type: mixing BigInt and Number, for example 1n and 1, throws a TypeError.

Do not confuse >>= with >>, which does not write back its result, or with >>>=, which fills from the left with zeros and does not support BigInt. The example demonstrates sign preservation, the assignment expression's value, and shift-count reduction for Number.

Examples

let value = -9;
const result = (value >>= 1);
console.log(value, result);

let wrapped = 64;
wrapped >>= 33;
console.log(wrapped);

let big = -9n;
big >>= 1n;
console.log(String(big));

Result

-5 -5
32
-5

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources