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

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

    It seems that isNaN() is not supported in Node.js out of the box.
    I worked around with

    var value = 1;
    if (parseFloat(stringValue)+"" !== "NaN") value = parseFloat(stringValue);
    

提交回复
热议问题