1
laobubu 2018-09-21 22:02:55 +08:00
console.log(2|(1+"sgdj")) // (1+"sgdj") 不能转换为 Int32
console.log(2|(1+"\n")) // (1+"\n") 转换为数字的时候,"\n"当空白字符去掉了 关于字符串转换为数字,可以参考: - https://www.ecma-international.org/ecma-262/5.1/#sec-9.5 - https://www.ecma-international.org/ecma-262/5.1/#sec-9.3 |
2
laobubu 2018-09-21 22:04:17 +08:00
@laobubu #1 (1+"sgdj") 应该说是不能转换为数字,只能得到个 NaN,然后根据 toInt32 的规则,NaN 就当作 0 参与位运算了
|
3
azh7138m 2018-09-21 22:08:29 +08:00 via Android
"1sgdj"被转换成了 NaN to int32 就是+0
"1\n"被转换成了 1 参照 https://tc39.github.io/ecma262/#sec-binary-bitwise-operators https://tc39.github.io/ecma262/#sec-toint32 |
4
azh7138m 2018-09-21 22:08:56 +08:00 via Android
哎呀,前面的老哥速度这么快的。。。
|