How do you check that a number is NaN in JavaScript?

前端 未结 30 3135
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 06:19

I’ve only been trying it in Firefox’s JavaScript console, but neither of the following statements return true:

parseFloat(\'geoff\') == NaN;

parseFloat(\'ge         


        
30条回答
  •  被撕碎了的回忆
    2020-11-22 06:40

    As of ES6, Object.is(..) is a new utility that can be used to test two values for absolute equality:

    var a = 3 / 'bar';
    Object.is(a, NaN); // true
    

提交回复
热议问题