JavaScript false values and operators. If you want to learn about JavaScript, you can check them.
JavaScriptThe list of false values is as follows,
Value |
Type |
0 |
Number |
NaN (Non-numeric) |
Number |
''(Null String) |
String |
False |
Boolean |
Null |
Object |
Undefined |
Undefined |
The above values will all be false values as judgment conditions, such:
The Code is as follows:
If (undefined ){
Alert ('undefined'); // This line of code will not be executed
}
While (null)
{
Alert ('null'); // This line of code will not be executed
}
Although all these values are equivalent to false, they are not interchangeable.
The following are some examples:
Undefined === null // false
Undefined = null // true
Even
NaN = NaN // false
NaN = NaN // false
PS: NaN and NaN are not equal to each other. You can use IsNaN (NaN) to solve the NaN judgment problem.
= (! =) The operator performs forced type conversion, and the conversion rules are quite strange. The following are some examples.
The Code is 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 that you use = (! =) Operator.