Use the shift left operator in JavaScript

Description

The following code shows how to use the shift left operator.

Example


<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
<!--from   w w  w . ja  va2 s  .  co  m-->
// 2 = 00000000000000000000000000000010
// 8 = 00000000000000000000000000001000
var x = 2 << 2;
document.write("2 << 2 = ",x);

</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use the shift left operator in JavaScript