Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upBasis for `no-self-compare`? #374
Comments
This comment has been minimized.
This comment has been minimized.
|
Use isNaN(). 'x === x' is confusing. On Friday, January 8, 2016, Nelo Mitranim notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
Questionable advice. |
This comment has been minimized.
This comment has been minimized.
|
@mitranim how is |
This comment has been minimized.
This comment has been minimized.
|
@dcousens the mdn link that @mitranim posted has details on the issue I presume is the reference here. I don't have any opinion on this matter though. EDIT: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN |
This comment has been minimized.
This comment has been minimized.
|
Right, so |
This comment has been minimized.
This comment has been minimized.
|
By broken I mean it doesn't tell you if a value is exactly Let's say you're implementing a deep tree comparison algorithm for something like function sameValueZero (one, other) {
return one === other ||
typeof one === 'number' && isNaN(one)
typeof other === 'number' && isNaN(other)
}Verbose! With self-compare: function sameValueZero (one, other) {
return one === other || one !== one && other !== other
} |
This comment has been minimized.
This comment has been minimized.
|
Seems clever enough to warrant a function/module with some semantic value but maybe there are performance concerns. I'm |
This comment has been minimized.
This comment has been minimized.
|
See the rule page for a more complete explanation of the rationale. This is a good default for 99%+ of users. If you still want to use
|
feross
closed this
Jan 8, 2016
This comment has been minimized.
This comment has been minimized.
Nope, and in this case, you don't even need a comment, you can just use the |
mitranim commentedJan 7, 2016
Comparing to self is the best way to test for NaN:
The
no-self-comparerule included into standardjs complains about this being "potentially pointless". I think it's wrong.