Comments (7)
No. We are looking at a better alternative to isNaN in a later edition. In the meantime, I cannot recommend the false equality trick.
from jslint.
isNaN
and isFinite
are inadequate in their current forms: not only can they be implemented in terms of the standard equality operators, but their automatic coercion of their arguments to numbers is unnecessary at best and unexpected at worst.
As @douglascrockford noted, the spec recognizes that a better alternative is needed; see the note in section 15.1.2.4:
A reliable way for ECMAScript code to test if a value
X
is aNaN
is an expression of the formX !== X
. The result will be true if and only ifX
is aNaN
.
from jslint.
@yahelc In the meantime, I would recommend overwriting the global isNaN
and isFinite
functions with the following:
function isNaN(value) {
return value != value;
}
function isFinite(value) {
return value == value && value != 1 / 0 && value != -1 / 0;
}
from jslint.
That is terrible advice.
from jslint.
Replacing the global isNaN with your own could make for some confusing and surprising code, for sure. Strongly agree not to do that.
The inequality check clearly works as specified; what's your reason for recommending against it?
isNumberNaN = (typeof x == "number" && x !== x);
from jslint.
typeof x === 'number' && isNaN(x)
from jslint.
Yep. Clearer, less thinking req'd, no comment needed. Can fail if somebody messes with global isNaN
.
from jslint.
Related Issues (20)
- Bug report: Your title here HOT 1
- Feature request: Spread syntax support in object literals HOT 4
- warnings that should be ignored sometiems suppress legitimate warnings
- Feature request: Tabs not spaces HOT 7
- Feature request: relaxing fart functions limitations HOT 4
- JSLint doesn't like named capture-groups for regular expressions HOT 2
- https://github.com/jslint-org/jslint/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=Feature+request%3A+Your+title+here HOT 1
- https://github.com/jslint-org/jslint/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=Feature+request%3A+Your+title+here
- JavaScript Classes ? HOT 1
- Feature request: vscode-jslint – lint on save (or lint automatically) HOT 1
- JSLint error on Side effect import HOT 1
- JSLint error on literal character in a character class (square brackets) HOT 3
- JSLint error on Private class features HOT 1
- Bug report: Don't support async await HOT 1
- Bug report: Your title here HOT 1
- Allow detect when function argument shadows existing variable HOT 4
- Bug report: Version broken in pip HOT 1
- Website issue: Your title here HOT 1
- Bug report: Your title here HOT 1
- Bug report: Your title here HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jslint.