Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Left shift operator (<<)

The << operator shifts bits to the left. For Number it operates on signed 32-bit integers and reduces the shift count modulo 32. BigInt has neither restriction; both operands must have matching numeric types.

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

value << count

The expression value << count shifts the bits of value left, filling vacated positions on the right with zeros. It returns a new value without modifying value itself. Operands undergo numeric conversion; afterward, both must be Number or both must be BigInt. Mixing these types, such as 1n << 2, throws TypeError.

For Number, the left operand is converted using ToInt32 and the right using ToUint32; the shift count is then reduced modulo 32. Bits shifted beyond the 32 positions are discarded, and the result is interpreted as a signed integer. Thus, 1 << 31 produces -2147483648, while 1 << 32 produces 1. Fractional parts of operands are discarded during conversion. Even value << 0 can therefore change the value.

For BigInt, the shift count is not reduced modulo 32, and there is no truncation to 32 bits. A nonnegative count corresponds to multiplication by the appropriate power of two. A negative count means a sign-preserving right shift: -5n << -1n produces -3n, the division result rounded down rather than toward zero.

Use << for deliberate bit manipulation, such as building masks. Do not substitute it for ordinary multiplication without accounting for conversion, discarded bits, and wrapping of the shift count for Number.

Examples

const results = [
  5 << 2,
  1 << 31,
  1 << 32,
  String(1n << 32n),
  String(-5n << -1n)
];
console.log(results.join('\n'));

Result

20
-2147483648
1
4294967296
-3

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