-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Disallow comparison against NaN
#49962
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
Comments
Are there any such languages? |
I didn't know that, all my life I thought it was one of quirks of JavaScript, so I supposed there are such languages since there are so many of them now. Now I doubt there are such languages. |
A syntactic check that |
Zeroing in on checking RHS, is there precedent for ignoring specific checks on LHS of equality checks? It's a bit uglier to write |
Everything costs some amount of performance and I think the set of people weird enough to write constants-on-the-left are the people who know better than to put |
Just a side note: |
TypeScript now errors on Thanks @a-tarasyuk! |
Suggestion
π Search Terms
disallow NaN
comparing with NaN
disallow comparing NaN
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Similar to #45978 . So the error should be something like
The condition will always return 'false' since NaN !== NaN. Use Number.isNaN.
π Motivating Example
or what has actually happened to me:
π» Use Cases
Since NaN is very rare, a programmer could forget to use
Number.isNaN(variable)
, and accidentally use===
.Or a programmer could have never even learned this, and just applies knowledge from other langs where NaN === NaN.
The text was updated successfully, but these errors were encountered: