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

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

    You should use the global isNaN(value) function call, because:

    • It is supported cross-browser
    • See isNaN for documentation

    Examples:

     isNaN('geoff'); // true
     isNaN('3'); // false
    

    I hope this will help you.

提交回复
热议问题