这个算子意味着什么"<< ="?

时间:2016-01-12 11:13:55

标签: javascript operators

我试图阅读这个javascript代码但我不确定它由于我以前从未见过的这个运算符所做的事情。截至目前,我无法测试代码。 <&LT =

<!DOCTYPE html>
<html>
<body>
<script>
var temp = 14;
var y = 2;
temp <<= y;
document.write(temp);
</script>
</body>
</html>

3 个答案:

答案 0 :(得分:3)

这是左移位赋值运算符,它是此语句的快捷方式:

temp = temp << y;

位移<<运算符采用temp的二进制表示(1110)并将其向左移y次(您可以将其视为将y个零附加到右侧。 <<发生后,1110变为111000,十进制为56

答案 1 :(得分:0)

x&lt;&lt; = y是左移的捷径:x = x&lt;&lt; ÿ

  

向左移位二进制表示b(<32)位,移位   从右边的零。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators

答案 2 :(得分:0)

In the java Script "<<=" is Left shift assignment operator that moves the specified amount of bits to the left and assigns the result to the variable.

You can find Description here