[問題] 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