Home >Web Front-end >JS Tutorial >Introduction to Truthy and Falsy in JavaScript_javascript skills
Like most programming languages, there is a boolean type in JavaScript for logical judgment. However, unlike many other programming languages, JavaScript has the concepts of Truthy values and Falsy values - except for the boolean values true and false, all types of JavaScript values can be used for logical judgments. The rules are as follows:
1. All Falsy values are false when making logical judgments. Falsy values include: false, undefined, null, positive and negative 0, NaN, "".
2. All other values are Truthy and are true when logical judgment is made. It is worth noting that Infinity, empty array, and "0" are all Truthy values.
Experiment
var y = [];
if(y){
"empty array is Truthy."
} else {
"empty array is Falsy."
}