Why does typeof NaN return 'number'?

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

    NaN stands for Not a Number. It is a value of numeric data types (usually floating point types, but not always) that represents the result of an invalid operation such as dividing by zero.

    Although its names says that it's not a number, the data type used to hold it is a numeric type. So in JavaScript, asking for the datatype of NaN will return number (as alert(typeof(NaN)) clearly demonstrates).

提交回复
热议问题