Bitwise shift left then assign (<<=) (Operator/assignment)

Destructively bitwise leftwards shift the first of two operands.

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise Server - 2.0
Opera browser - 3.0
Property/method value type:Number primitive
JavaScript syntax:-anOperand1 <<= anOperand2
Argument list:anOperand1A value to be shifted and assigned to
anOperand2A distance to shift anOperand1

Bitwise shift leftwards the left operand by the number of bits in the right operand and assign the result to the left operand.

This is functionally equivalent to the expression:

anOperand1 = anOperand1 << anOperand2;

The bitwise shift left operator converts it left operand to a 32 bit integer and moves it leftwards by the number of bits indicated by the right operand.

As the value is shifted leftwards, bits that roll out of the left end of the register are discarded. The right-hand end of the register is filled with zero bits. Shifting leftwards by 32 bits will fill the buffer with all zero bits.

Because the value is converted to an integer, any fractional part is discarded as the shift begins.

The right hand operand is converted to a 5-bit value with a bitwise mask to limit the distance of the shift to 32 bits. This can cause unexpected results if the right-hand side is derived from an expression that may yield a value larger than 32.

Although this is classified as an assignment operator it is really a compound of an assignment and a bitwise operator.

The associativity is right to left.

Refer to the operator precedence topic for details of execution order.

The new value of anOperand1 is returned as a result of the expression.

Warnings:

See also:Assignment operator, Associativity, Bit-field, Bitwise operator, Bitwise shift left (<<), Bitwise shift operator, Bitwise shift right (>>), Bitwise shift right and assign (>>=), Bitwise unsigned shift right (>>>), Bitwise unsigned shift right and assign (>>>=), LValue, Operator Precedence, Shift operator

insert figure 0017

Cross-references:

ECMA 262 edition 2 - section - 11.13

ECMA 262 edition 3 - section - 11.13