2
A
回答
10
这是因为~
是一个数值运算符,所以它转换null
到0
第一:
> ~0
-1
这将相当于该表达式:
~(+null)
同样:
> ~[]
-1
> ~{}
-1
1
首先,~
是一个按位运算符NOT
。这意味着它翻转数字表示中的所有位。 0010 1010
变成1101 0101
。
作为使用2的补码,用于存储数字计算机的结果,这个等式成立:
~number == -number - 1
如可以从我以前的例子来示出:
0010 1010
(这代表数42
)
1101 0101
(这代表号码-43
)
现在,因为~
是一个操作数字的运算符,所以它的参数首先被转换为数字。由于null
被转换为0
,因此得到-1
(根据上述等式)。
+0
+1实际解释如何工作 – miraculixx
相关问题
- 1. 为什么1 = NULL和1!= NULL的结果是一样的?
- 2. Javascript - 为什么NaN(1 + null)返回false?
- 3. 为什么count函数为false返回1,为NULL为0
- 4. 为什么yylval null?
- 5. JavaFX TreeView为null为什么?
- 6. 为什么null参考打印为“null”
- 7. 为什么铸造Object(null)不为null?
- 8. 为什么DataGridViewRow.Cells [1] .Value在它不为空时返回null?
- 9. 什么是/ dev/null 2>&1?
- 10. 为什么mSuggestedFriends为null?
- 11. getClass()。getClassLoader()为null,为什么?
- 12. 为什么listOfFiles为null?
- 13. 为什么getFacesContext()变为null
- 14. 为什么“1”等于“+1”?
- 15. 为什么[1,[2,3] = [1,[2,3]]
- 16. findViewById返回null - 为什么?
- 17. 为什么RedirectToAction返回null?
- 18. getReadableDatabase为什么返回null?
- 19. 为什么Uitextfield返回null?
- 20. 为什么“curl_exec”打印“null”?
- 21. FormattedText.GetMaxTextWidths返回null - 为什么?
- 22. MenuItem + CommandParameter = null!为什么?
- 23. 为什么Geocoder.getFromLocationName返回null?
- 24. 为什么SelectSingleNode返回null?
- 25. 为什么getSelectedItem返回null?
- 26. NSDateFormatter生成(null) - 为什么?
- 27. 为什么findByViewId返回null?
- 28. 为什么cookie.getMaxAge()= -1?
- 29. 为什么AVCodecContext extradata是NULL?
- 30. 为什么user_id列是NULL?
'tilde'是一个[** Bitwise NOT Operator **](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators#.7E_(Bitwise_NOT)) - 正如在文档中看到的那样:“按位注释任意数字x产生 - (x + 1)”。例如,〜5产生-6.' - 因此,变成'0'的'null/undefined'是' - (0 + 1)',产生'-1' – Nope
你的断言不一定是真的,它取决于微处理器的体系结构。 –