Why does typeof NaN return 'number'?

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

    The value NaN is really the Number.NaN hence when you ask if it is a number it will say yes. You did the correct thing by using the isNaN() call.

    For information, NaN can also be returned by operations on Numbers that are not defined like divisions by zero or square root of a negative number.

提交回复
热议问题