Why does typeof NaN return 'number'?

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

    The ECMAScript (JavaScript) standard specifies that Numbers are IEEE 754 floats, which include NaN as a possible value.

    ECMA 262 5e Section 4.3.19: Number value

    primitive value corresponding to a double-precision 64-bit binary format IEEE 754 value.

    ECMA 262 5e Section 4.3.23: NaN

    Number value that is a IEEE 754 "Not-a-Number" value.

    IEEE 754 on Wikipedia

    The IEEE Standard for Floating-Point Arithmetic is a technical standard established by the Institute of Electrical and Electronics Engineers and the most widely used standard for floating-point computation [...]

    The standard defines

    • arithmetic formats: sets of binary and decimal floating-point data, which consist of finite numbers (including signed zeros and subnormal numbers), infinities, and special "not a number" values (NaNs)

    [...]

提交回复
热议问题