Why does typeof NaN return 'number'?

前端 未结 21 1516
误落风尘
误落风尘 2020-11-22 05:38

Just out of curiosity.

It doesn\'t seem very logical that typeof NaN is number. Just like NaN === NaN or NaN == NaN returning

21条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 06:41

    You've got to love Javascript. It has some interesting little quirks.

    http://wtfjs.com/page/13

    Most of those quirks can be explained if you stop to work them out logically, or if you know a bit about number theory, but nevertheless they can still catch you out if you don't know about them.

    By the way, I recommend reading the rest of http://wtfjs.com/ -- there's a lot more interesting quirks than this one to be found!

提交回复
热议问题