【问题标题】:what is the difference between isNaN and Number.isNaN? [duplicate]isNaN 和 Number.isNaN 有什么区别? [复制]
【发布时间】:2018-11-19 19:15:38
【问题描述】:

isNaN 和 Number.isNaN 有什么区别?

isNaN('hello world'); // returns 'true'.
Number.isNaN('hello world'); // returns 'false

【问题讨论】:

    标签: javascript


    【解决方案1】:

    规范是处理这种微妙之处的好地方。 isNaN 尝试将其参数转换为数字; Number.isNaN 没有,如果其参数的类型不是 "number",则返回 false。所以:

    console.log(isNaN("%"));        // true, coerced to number and result was NaN
    console.log(Number.isNaN("%")); // false, not coerced

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-30
      • 2015-11-23
      • 2013-02-13
      • 2011-04-26
      • 2016-09-24
      • 1970-01-01
      相关资源
      最近更新 更多