In JavaScript, truthy and falsy values determine how non-boolean values behave in boolean contexts — like if conditions or logical operators.
Every value in JavaScript is either truthy (treated as true) or falsy (treated as false) when evaluated in a boolean expression.
1️⃣ Falsy Values
These values are considered false when converted to a boolean.
false
0
-0
0n // BigInt zero
"" // Empty string
null
undefined
NaN
Example:
if (0) console.log("Truthy");
else console.log("Falsy"); // Output: Falsy
There are only 7 falsy values in JavaScript — everything else is truthy.
2️⃣ Truthy Values
All values other than falsy are treated as true.
Examples include:
true
"hello" // non-empty string
42 // any non-zero number
[] // empty array
{} // empty object
function() {} // any function
Example:
if ("JavaScript") console.log("Truthy"); // Output: Truthy
3️⃣ Boolean Conversion
You can test a value’s truthiness using Boolean() or !!:
console.log(Boolean(0)); // false
console.log(Boolean("Hi")); // true
console.log(!!undefined); // false
console.log(!![]); // true
💡 In Short:
Truthy values evaluate to
true, and falsy values evaluate tofalsein boolean contexts.
✅ Only 7 values are falsy (false, 0, -0, 0n, "", null, undefined, NaN), everything else is truthy.