In JavaScript, except for NaN, are all other variables equal to itself?
学习ing
学习ing 2017-07-05 10:50:13
0
4
1424

How does javascript quickly determine whether the value of a variable val is NaN? If, except for NaN, all other variables are equal to itself, then just judge val===val directly?

学习ing
学习ing

reply all(4)
刘奇

NaN is the only non-reflexive value in JavaScript, which is

NaN === NaN // false

This book mentions:

NaN is a very special value in that it's never equal to another NaN value (i.e., it's never equal to itself). It's the only value, in fact, that is not reflexive (without the Identity characteristic x === x) . So, NaN !== NaN.

JavaScript you don’t know

女神的闺蜜爱上我

Yes, NaN can be judged using isNaN or whether it is equal to yourself

At the same time, conversely, if two variables are equal to determine whether the two variables are the same, there are special cases of +0 and -0, and use the reciprocal to determine whether they are equal.

阿神
let a = []
let b = []

console.log(a===b)

Would you like to give the question a try?

曾经蜡笔没有小新

ES6 provides a new Number.isNaN() method on the Number object. It is recommended to use Number.isNaN() directly to check whether a value is NaN.
In addition, except for the cases of +0 and -0, === meets the needs. A better way is to use Object.is()

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template