[問題] Why NaN and Infinity are classified as the type of numbe

看板Ajax作者 (自由人371)時間7年前 (2017/07/21 14:10), 編輯推噓6(602)
留言8則, 7人參與, 最新討論串1/1
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://www.ptt.cc/bbs/Ajax/M.1500617454.A.083.html

07/21 14:19, , 1F
不然你覺得是什麼type?
07/21 14:19, 1F

07/21 14:32, , 2F
實作上來說這些只是特別的數字,可參考IEEE754
07/21 14:32, 2F

07/21 22:58, , 3F
NaN is number type, and NaN != NaN
07/21 22:58, 3F

07/22 01:27, , 4F
白馬是馬,白馬也非馬,就這個意思
07/22 01:27, 4F

07/24 10:07, , 5F
樓上不如講 色即是空,空即是色
07/24 10:07, 5F

07/24 15:20, , 6F
就像 '' 也是 string 啊,明明就是空的東西
07/24 15:20, 6F

07/25 22:33, , 7F
浮點數裡有定義 NaN ,所以在 C 裡也能用。
07/25 22:33, 7F

07/30 03:24, , 8F
null 也是 object 阿
07/30 03:24, 8F
文章代碼(AID): #1PSPhk23 (Ajax)
文章代碼(AID): #1PSPhk23 (Ajax)