Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/operators/bit.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ toInt32(Math.pow(2, 32) - 1) // -1

位运算只对整数有效,遇到小数时,会将小数部分舍去,只保留整数部分。所以,将一个小数与`0`进行二进制或运算,等同于对该数去除小数部分,即取整数位。

使用二进制或运算取整,是所有取整方法中最快的一种。

```javascript
2.9 | 0 // 2
-2.9 | 0 // -2
Expand Down Expand Up @@ -110,7 +112,6 @@ toInt32(Math.pow(2, 32) - 1) // -1
~~3 // 3
```

使用二进制否运算取整,是所有取整方法中最快的一种。

对字符串进行二进制否运算,JavaScript 引擎会先调用`Number`函数,将字符串转为数值。

Expand Down