the fake values for JavaScript are listed below,
Value |
type |
0 |
Number |
NaN ( non-numeric ) |
Number |
' ( empty string ) |
String |
False |
Boolean |
Null |
Object |
Undefined |
Undefined |
The above values are false values as a criterion, such as:
Copy Code code as follows:
if (undefined) {
Alert (' undefined '); This line of code does not execute
}
while (null)
{
Alert (' null '); This line of code does not execute
}
Although all of these values are equivalent to false, they are not interchangeable.
Some examples are listed below:
undefined = = NULL//false
undefined = = NULL//true
Even
Nan = = Nan//false
Nan = = Nan//false
Ps:nan and Nan are not equal in either operation, isNaN (Nan) can be used to solve the problem of Nan's judgment.
the = = = (!=) operator enforces type conversions, and the conversion rules are quite bizarre. Here are some examples.
Copy Code code as follows:
' = = ' 0 '//False
0 = = ""/True
0 = ' 0 '/True
False = = ' false '//False
false = = ' 0 '/True
false = = undefined//False
false = = NULL//False
NULL = = undefined//True
' \t\r\n ' = 0//True
We recommend using the = = = = (!===) operator.