Why does typeof NaN return 'number'?

前端 未结 21 1217
误落风尘
误落风尘 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:40

    We could argue that NaN is a special case object. In this case, NaN's object represents a number that makes no mathematical sense. There are some other special case objects in math like INFINITE and so on.

    You can still do some calculations with it, but that will yield strange behaviours.

    More info here: http://www.concentric.net/~ttwang/tech/javafloat.htm (java based, not javascript)

提交回复
热议问题