Truthy & Falsy
Values that evaluate to true or false.
Examples
Checking Falsy
0 is a falsy value.
let x = 0;
if (x) {
console.log("Truthy");
} else {
console.log("Falsy");
}
// Output: FalsyChecking Truthy
Non-empty strings are truthy.
let name = "John";
if (name) {
console.log("Hello " + name);
} else {
console.log("Name is missing");
}
// Output: Hello JohnTest Your Knowledge
JavaScript Quiz
No quiz available for this topic yet.