-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
price === NaN 永远是个false #2036
price === NaN 永远是个false #2036
Conversation
js中 NaN!==NaN
所以文档标注这个写法是错的 |
那么 price !== NaN 不也永远是 true 么... 感觉文档没毛病 |
23c5d8e
to
689ecc9
Compare
先说观点:我也觉得原文档没毛病,所以这个修改是不必要的。 理由:
console.assert(NaN === NaN, 'ASSERT: NaN equals NaN'); // Assertion failed: ASSERT: NaN equals NaN
console.assert(Number.NaN === NaN, 'ASSERT: Number.NaN equals NaN'); // Assertion failed: ASSERT: Number.NaN equals NaN
console.assert('NotANumber' === NaN, 'ASSERT: String NotANumber equals NaN'); // Assertion failed: ASSERT: String NotANumber equals NaN
console.assert('1' === NaN, 'ASSERT: String 1 equals NaN'); // Assertion failed: ASSERT: String 1 equals NaN
console.assert(1 === NaN, 'ASSERT: Number 1 equals NaN'); // Assertion failed: ASSERT: Number 1 equals NaN
console.assert(Infinity === NaN, 'ASSERT: Infinity equals NaN'); // Assertion failed: ASSERT: Infinity equals NaN
console.assert(true === NaN, 'ASSERT: Boolean true equals NaN'); // Assertion failed: ASSERT: Boolean true equals NaN
console.assert(false === NaN, 'ASSERT: Boolean false equals NaN'); // Assertion failed: ASSERT: Boolean false equals NaN
console.assert(null === NaN, 'ASSERT: Null equals NaN'); // Assertion failed: ASSERT: Null equals NaN
console.assert(undefined === NaN, 'ASSERT: Undefined equals NaN'); // Assertion failed: ASSERT: Undefined equals NaN
console.assert(NaN !== NaN, 'ASSERT: NaN not equal NaN'); // PASS
console.assert(Number.NaN !== NaN, 'ASSERT: Number.NaN not equal NaN'); // PASS
console.assert('NotANumber' !== NaN, 'ASSERT: String NotANumber not equal NaN'); // PASS
console.assert('1' !== NaN, 'ASSERT: String 1 not equal NaN'); // PASS
console.assert(1 !== NaN, 'ASSERT: Number 1 not equal NaN'); // PASS
console.assert(Infinity !== NaN, 'ASSERT: Infinity not equal NaN'); // PASS
console.assert(true !== NaN, 'ASSERT: Boolean true not equal NaN'); // PASS
console.assert(false !== NaN, 'ASSERT: Boolean false not equal NaN'); // PASS
console.assert(null !== NaN, 'ASSERT: Null not equal NaN'); // PASS
console.assert(undefined !== NaN, 'ASSERT: Undefined not equal NaN'); // PASS
console.assert(isNaN(NaN), 'ASSERT: isNaN(NaN)'); // PASS
console.assert(isNaN(Number.NaN), 'ASSERT: isNaN(Number.NaN)'); // PASS
console.assert(isNaN('NotANumber'), `ASSERT: isNaN('NotANumber')`); // PASS
console.assert(isNaN('1'), `ASSERT: isNaN('1')`); // Assertion failed: ASSERT: isNaN('1')
console.assert(isNaN(1), 'ASSERT: isNaN(1)'); // Assertion failed: ASSERT: isNaN(1)
console.assert(isNaN(Infinity), 'ASSERT: isNaN(Infinity)'); // Assertion failed: ASSERT: isNaN(Infinity)
console.assert(isNaN(true), 'ASSERT: isNaN(true)'); // Assertion failed: ASSERT: isNaN(true)
console.assert(isNaN(false), 'ASSERT: isNaN(false)'); // Assertion failed: ASSERT: isNaN(false)
console.assert(isNaN(null), 'ASSERT: isNaN(null)'); // Assertion failed: ASSERT: isNaN(null)
console.assert(isNaN(undefined), 'ASSERT: isNaN(undefined)'); // PASS
console.assert(Number.isNaN(NaN), 'ASSERT: Number.isNaN(NaN)'); // PASS
console.assert(Number.isNaN(Number.NaN), 'ASSERT: Number.isNaN(Number.NaN)'); // PASS
console.assert(Number.isNaN('NotANumber'), `ASSERT: Number.isNaN('NotANumber')`); // Assertion failed: ASSERT: Number.isNaN('NotANumber')
console.assert(Number.isNaN('1'), `ASSERT: Number.isNaN('1')`); // Assertion failed: ASSERT: Number.isNaN('1')
console.assert(Number.isNaN(1), 'ASSERT: Number.isNaN(1)'); // Assertion failed: ASSERT: Number.isNaN(1)
console.assert(Number.isNaN(Infinity), 'ASSERT: Number.isNaN(Infinity)'); // Assertion failed: ASSERT: Number.isNaN(Infinity)
console.assert(Number.isNaN(true), 'ASSERT: Number.isNaN(true)'); // Assertion failed: ASSERT: Number.isNaN(true)
console.assert(Number.isNaN(false), 'ASSERT: Number.isNaN(false)'); // Assertion failed: ASSERT: Number.isNaN(false)
console.assert(Number.isNaN(null), 'ASSERT: Number.isNaN(null)'); // Assertion failed: ASSERT: Number.isNaN(null)
console.assert(Number.isNaN(undefined), 'ASSERT: Number.isNaN(undefined)'); // Assertion failed: ASSERT: Number.isNaN(undefined) |
js中 NaN!==NaN