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

前端 未结 30 3200
伪装坚强ぢ
伪装坚强ぢ 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:49

    NaN === NaN;        // false
    Number.NaN === NaN; // false
    isNaN(NaN);         // true
    isNaN(Number.NaN);  // true
    

    Equality operator (== and ===) cannot be used to test a value against NaN.

    Look at Mozilla Documentation The global NaN property is a value representing Not-A-Numbe

    The best way is using 'isNaN()' which is buit-in function to check NaN. All browsers supports the way..

提交回复
热议问题