我在测试中看到了这道题,但我不明白运算符是如何处理语句的。
let a = ~-(2 + "2");
console.log(a);
最佳答案
~-(2 + "2")
- 0:
2 + "2"
(串联)="22"
- 1:
-"22"
(强制转换)=-22
- 2:
~-22
(按位非)= -(-22 + 1)= 21
Bitwise NOTing any number x yields -(x + 1). For example, ~-5 yields 4.
关于javascript - 为什么 ~-(2 + "2") 是 21?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48875711/