What does << mean in Javascript

This question already has an answer here:

  • What do “>>” and “<<” mean in Javascript? 10 answers
  • What are bitwise shift (bit-shift) operators and how do they work? 8 answers
  • what does << do in javascript [duplicate] 2 answers

  • It's the bitwise left shift operator. The operands are converted to 32-bit integers, the left operand's bits are shifted left by the number of positions defined by the right operand, and the expression's value is the result.

    Here's a simple example:

    var a = 1;
    var b = a << 2; // Move the bit left by two places
    console.log(b); // "4"
    

    That works because in a signed 32-bit integer, 1 looks like this in binary:

    00000001

    If you move that bit to the left two places:

    00000100

    ...you get 4 .

    链接地址: http://www.djcxy.com/p/12574.html

    上一篇: <<是什么意思在JavaScript中

    下一篇: <<什么意思在Javascript中