作者freeman371 (自由人371)
看板Ajax
标题[问题] Why NaN and Infinity are classified as the type of numbe
时间Fri Jul 21 14:10:51 2017
I have practiced Javascript for a long long time,
and there's always a contradiction, which has confused me so much.
That is, why NaN and Infinity are both types of “number”?
In mathematics,“Infinity”is just a concept, not a number.
“NaN”means“Not a number”on its literal meaning.
Obviously those are not“numbers.”
However, in Javascript, both“NaN”and“Infinity”are“number.”
You can try it like below:
typeof NaN // Returns“number”
typeof Infinity // Returns“number”
So what's the reason?
Could someone tell me the reason about this weird contradiction?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 42.145.142.148
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Ajax/M.1500617454.A.083.html
1F:→ ssccg: 不然你觉得是什麽type? 07/21 14:19
2F:→ ssccg: 实作上来说这些只是特别的数字,可参考IEEE754 07/21 14:32
3F:推 DolphinLinn: NaN is number type, and NaN != NaN 07/21 22:58
4F:推 aspdoctor: 白马是马,白马也非马,就这个意思 07/22 01:27
5F:推 Qiqi: 楼上不如讲 色即是空,空即是色 07/24 10:07
6F:推 visa9527: 就像 '' 也是 string 啊,明明就是空的东西 07/24 15:20
7F:推 hijkxyzuw: 浮点数里有定义 NaN ,所以在 C 里也能用。 07/25 22:33
8F:推 VdustR: null 也是 object 阿 07/30 03:24