What does << means in javascript

This question already has an answer here:

  • What are bitwise shift (bit-shift) operators and how do they work? 8 answers

  • It means bitwise left shift. Same as it means in most other programming languages.

    Some console test:

    >a = 2
    2
    >a << 1 
    4
    >a << 3
    16
    

    It's the bitwise left operator. In a << b , it shifts a in binary representation b (< 32) bits to the left, shifting in zeros from the right.

    Some examples:

    a = 1       // 00000001 in binary
    b = a << 1  // equals to 2, 00000010 in binary
    c = a << 2  // equals to 4, 00000100 in binary
    
    document.write('a << 1 = ' + b + '<br />'
                   + 'a << 2 = ' + c);
    链接地址: http://www.djcxy.com/p/12576.html

    上一篇: java中发生了什么'>>>'运算符?

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