什么<<在Math.random()中做什么* Math.pow(36,2)<< 0 [复制]

问题描述 投票:1回答:2

这个问题在这里已有答案:

想知道<<在这方面做了什么:

Math.random() * Math.pow(36, 2) << 0

不确定如何在实践中使用它。

javascript bit-shift
2个回答
1
投票

它截断数字/将其转换为整数。你可以自己测试一下:

console.log(12.345 << 0); // 12

- 这个问题与Why does a shift by 0 truncate the decimal?非常相似


0
投票

看看这个

a = Math.pow(36, 2)
1296
a = Math.random() * a
477.5906135469167
a = a << 0
477
© www.soinside.com 2019 - 2024. All rights reserved.