This question already has answers here:
What is the JavaScript >>> operator and how do you use it?

(7个答案)


5年前关闭。




我有一段我想了解的javascript代码
return ( n >>> 0 ) * 2.34e10;

那么>>>是什么意思?

预先感谢...这是我的第一个问题

最佳答案

这是一个zero-fill right shift。这不会对正整数或0产生任何影响,但会对负数做一些有趣的事情(因为most significant bit changes to zero)。

 2 >>> 0 === 2
 1 >>> 0 === 1
 0 >>> 0 === 0
-1 >>> 0 === 4294967295
-2 >>> 0 === 4294967294
-3 >>> 0 === 4294967293

应该指出的是(感谢安迪!),在进行移位之前,JavaScript converts the arguments to signed 32-bit integers进行了移位。因此,>>> 0本质上对正数执行Math.floor:
1.1 >>> 0 === 1
1.9 >>> 0 === 1

关于javascript - ' >>> '在javascript中是什么意思?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3734451/

10-12 00:31
查看更多