Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Q622】Number.isNaN 与 globalThis.isNaN 有何区别 #640

Open
shfshanyue opened this issue Jul 7, 2021 · 3 comments
Open

【Q622】Number.isNaN 与 globalThis.isNaN 有何区别 #640

shfshanyue opened this issue Jul 7, 2021 · 3 comments
Labels

Comments

@shfshanyue
Copy link
Owner

No description provided.

@shfshanyue shfshanyue added the js label Jul 7, 2021
@shfshanyue
Copy link
Owner Author

Number.isNaN(NaN)
isNaN(NaN)

Number.isNaN('NaN')
isNaN('NaN')

@nmsn
Copy link

nmsn commented Dec 1, 2021

Number.isNaN(NaN)
isNaN(NaN)

Number.isNaN('NaN')
isNaN('NaN')

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

@HydratedPig
Copy link

还真没注意过,看了下 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 不会对输入的参数进行强制转换

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants