The conversion rules for converting to a Boolean value in javascript are as follows:
1. The special values undefined and null are changed to false.
2. The numbers 0 and NaN change to false.
3. Convert the null string to false.
4. All other values are changed to true.
Where
The undefined value has three conditions:
1. You declared a variable but did not assign a value to it. For example,
<Script>
Var;
Alert ();
</Script>
<Script>
Var;
Alert ();
</Script>
2. You have accessed an attribute that has not been declared by the object (in javascript, You can regard everything as an attribute of the object), for example:
<Script>
Var test = new Object ();
Test. a = "apple ";
Test. B = "orange ";
Alert (test. c );
</Script>
<Script>
Var test = new Object ();
Test. a = "apple ";
Test. B = "orange ";
Alert (test. c );
</Script>
Test. c is not declared.
3. You have defined the function parameter but have not passed the value to it. For example:
<Script>
Function test (ob ){
Alert (ob );
}
Test ();
</Script>
<Script>
Function test (ob ){
Alert (ob );
}
Test ();
</Script>
NaN (non-numeric value) is generated when the value cannot be converted into a number, for example:
<Script>
Var string = "I am a student ";
Var number = 42;
Alert (string * number );
</Script>
<Script>
Var string = "I am a student ";
Var number = 42;
Alert (string * number );
</Script>
One of the elegant features of javascript is that it is easy to convert a value from one data type to another. For example:
<Script>
Var a = 4;
Var B = '3 ';
Var c = a * B;
Alert (c );
</Script> www.2cto.com
<Script>
Var a = 4;
Var B = '3 ';
Var c = a * B;
Alert (c );
</Script> the preceding Code triggers data type conversion. The multiplication operator requires a number, so javascript tries to convert it to a number as much as possible. In the preceding example, It is easy: B is interpreted as number 3, so c is changed to 12.
From the cangkukuaimanle Column