极客时间返利平台,你可以在上边通过山月的链接购买课程,并添加我的微信 (shanyue94) 领取返现。
山月训练营之面试直通车 服务上线了,从准备简历、八股文准备、项目经历准备、面试、面经、面经解答、主观问题答复、谈薪再到入职的一条龙服务。

# Number.isNaN 与 globalThis.isNaN 有何区别

Issue

欢迎在 Gtihub Issue 中回答此问题: Issue 640 (opens new window)

Number.isNaN(NaN);
isNaN(NaN);

Number.isNaN("NaN");
isNaN("NaN");

Author

回答者: nmsn (opens new window)

Number.isNaN(NaN);
isNaN(NaN);

Number.isNaN("NaN");
isNaN("NaN");

试了下 Number.isNaN('NaN')false,其他都是 true

还真没注意过,看了下 MDN,上面解释已经很明示了

  • isNaN:

    Return Value: true if the given value is NaN after being converted to a number; otherwise, false.

  • Number.isNaN:

    Return value: The boolean value true if the given value is a number with value NaN. Otherwise, false.

globalThis.isNaN 会对参数进行强制转换后判断是不是 NaN,而 Number.isNaN 不会对输入的参数进行强制转换

Last Updated: 2/13/2023, 10:50:25 AM