This article mainly introduces Truthy and Falsy in JavaScript, And the Truthy and Falsy values in JavaScript. This article describes related concepts, for more information, see the boolean Type in JavaScript, which is the same as that in most programming languages. However, unlike many other programming languages, JavaScript has the concept of Truthy and Falsy-all types of JavaScript values except boolean values true and false can be used for logical judgment, the rules are as follows:
1. All Falsy values are false when logical judgment is performed. Falsy values include: false, undefined, null, plus or minus 0, NaN, and ,"".
2. All other values are Truthy. true is used for logical judgment. It is worth noting that Infinity, an empty array, and "0" are all Truthy values.
Lab
The Code is as follows:
Var x = "0 ";
If (x ){
"String 0 is Truthy ."
} Else {
"String 0 is Falsy ."
}
Var y = [];
If (y ){
"Empty array is Truthy ."
} Else {
"Empty array is Falsy ."
}