CKTIS / JavaScript
Left shift assignment (<<=)
The `<<=` operator shifts a value's bits to the left and assigns the result to the target. The value stored in the target can differ from the shift result. The shift uses 32 bits for `Number` but does not truncate `BigInt` results to 32 bits.
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 <<= shiftCounttarget <<= shiftCount reads the target's value, performs the << shift, and assigns the result to the target. The expression evaluates to the shift result, even if writing to the target converts that value. For example, if a Uint8Array element contains 128, shifting it left by one bit with <<= yields 256 as the expression's value but stores 0 in the element. The expression resembles target = target << shiftCount, but evaluates the left-hand side only once—important for property access with side effects. The target must allow assignment; a variable declared with const cannot be updated this way.
For Number, the left value is converted to a signed 32-bit integer. The count is converted to an unsigned 32-bit integer and then reduced modulo 32. Zeros enter from the right, and bits shifted beyond the 32 positions are discarded. Thus, shifting by 32 acts like shifting by 0, and the result can be negative. This is not a general replacement for multiplying by a power of two.
After numeric conversion, both operands must be Number or both must be BigInt; mixing these types throws TypeError. For BigInt, there is no 32-bit truncation or modulo-32 reduction of the count, and a negative count means shifting right.
In the example, shifting 3 by 2 produces 12; result receives that same value. The wrapped case demonstrates modulo-32 count reduction, while wide demonstrates the absence of 32-bit truncation for BigInt.
Examples
let mask = 3;
const result = (mask <<= 2);
console.log(mask, result);
let wrapped = 1;
wrapped <<= 32;
console.log(wrapped);
let wide = 1n;
wide <<= 32n;
console.log(String(wide));Result
12 12 1 4294967296
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.