In JavaScript, except for NaN, are all other variables equal to itself?
学习ing2017-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?
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.
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.
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()
NaN is the only non-reflexive value in JavaScript, which is
This book mentions:
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.
Would you like to give the question a try?
ES6 provides a new
Number.isNaN()
method on theNumber
object. It is recommended to useNumber.isNaN()
directly to check whether a value isNaN
.In addition, except for the cases of
+0
and-0
,===
meets the needs. A better way is to useObject.is()