Why does typeof NaN return 'number'?

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

    If using jQuery, I prefer isNumeric over checking the type:

    console.log($.isNumeric(NaN));  // returns false
    console.log($.type(NaN));       // returns number
    

    http://api.jquery.com/jQuery.isNumeric/

提交回复
热议问题