Shift out of range¶
Use standard library functions such as
Math.pow to perform the required shifting. Alternatively, you can use the BigInt type if it is available on your platform.
The following code snippet attempts to assign
x the value 240 (1099511627776). In fact, however, the left operand
1 is only shifted by
8 (that is, 40 modulo 32), so
x ends up being assigned the value 28 (256).
var x = 1<<40;
A better solution would be to use
Math.pow as follows:
var x = Math.pow(2, 40);