[问题] Why NaN and Infinity are classified as the type of numbe

楼主: freeman371 (自由人371)   2017-07-21 14:10:51
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?
作者: ssccg (23)   2017-07-21 14:19:00
不然你觉得是什么type?实作上来说这些只是特别的数字,可参考IEEE754
作者: DolphinLinn (怕水海豚)   2017-07-21 22:58:00
NaN is number type, and NaN != NaN
作者: aspdoctor (大崎)   2017-07-22 01:27:00
白马是马,白马也非马,就这个意思
作者: Qiqi (泼泼)   2017-07-24 10:07:00
楼上不如讲 色即是空,空即是色
作者: visa9527 (高级伴读士官长)   2017-07-24 15:20:00
就像 '' 也是 string 啊,明明就是空的东西
作者: hijkxyzuw (i,j,k) ×(x,y,z)   2017-07-25 22:33:00
浮点数里有定义 NaN ,所以在 C 里也能用。
作者: VdustR (京)   2017-07-30 03:24:00
null 也是 object 阿

Links booklink

Contact Us: admin [ a t ] ucptt.com