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?
怪我咯2017-07-05 10:52:13
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
女神的闺蜜爱上我2017-07-05 10:52:13
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.
阿神2017-07-05 10:52:13
let a = []
let b = []
console.log(a===b)
Would you like to give the question a try?
曾经蜡笔没有小新2017-07-05 10:52:13
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()