1. Value of Ture or False
The value of the Boolean type that will be implicitly converted to false in the If judgment has false, 0, undefined, null, ' ', NaN (not a number)
Besides the other values will be considered true, including ' 0 ', ' false ', empty function, empty array ([]), Empty object ({})
var a =!! (0);//equivalent to var a = False;var a =!! (' 0 '); Equivalent to var a = true;
2. Comparison of Falsy values
The value is false, ', 03 is the value comparison, as follows:
Alert (false = = ");//truealert (false = = 0);//truealert (0 = =");//true
False, ", 0, compared to undefined, NULL, the result is as follows:
Alert (false = = undefined);//falsealert ("= = null);//falsealert (" = = = undefined);//false
alert (undefined = = undefined);//truealert (null = = null);//true
As you can see,0, ', false, the three values are equal, Undefinde, and Null is different from any other type of value compared to itself.
The comparison between Nan and other types of falsy values is as follows:
Alert (false = = Nan);//falsealert (0 = = Nan);//falsealert ("= = Nan);//falsealert (undefined = = Nan);//falsealert (null = = Nan);//falsealert (nan = = nan);//false
The result is thatnan is not equal to any type of value, including itself . How to determine the value of a Nan type
Alert (typeof (Nan));//numberalert (IsNaN (Nan));//true
False values in JavaScript and their common comparison operations