Skip to content

Truthy & Falsy Values

In JavaScript, every value has an inherent boolean “truthiness” — it’s either truthy (evaluates to true in a boolean context) or falsy (evaluates to false).

Truthy/falsy checks are used everywhere: if statements, logical operators &&/||, and ternary expressions. Understanding them is key to writing clean conditional logic.

There are exactly 6 falsy values in JavaScript:

false; // the boolean false
0; // zero
''; // empty string
null; // null
undefined; // undefined
NaN; // Not a Number

Everything else is truthy:

true;
1; // any non-zero number
'hello'; // any non-empty string
[]; // empty array
{}; // empty object
function(){}; // any function
'false'; // the string "false" — truthy!
flowchart TD
Value[Is this value falsy?]
Check{"Value === false / 0 / '' / null / undefined / NaN?"}
Yes["⬇️ Evaluates to false"]
No["⬇️ Evaluates to true"]
Value --> Check
Check -->|Yes| Yes
Check -->|No| No
// Default values with ||
const name = userInput || 'Guest';
// If userInput is falsy (empty, null, undefined), use 'Guest'
// Guard with &&
isLoggedIn && renderDashboard();
// Only render if isLoggedIn is truthy
// ❌ Wrong
if (value == false) { } // Too broad — catches 0 and ''
// ✅ Right
if (value === false) { } // Only actual false
// ❌ Wrong — 0 is falsy
if (score) { } // Fails when score is 0
// ✅ Right
if (score !== null && score !== undefined) { }
  • Only 6 falsy values: false, 0, '', null, undefined, NaN
  • Everything else is truthy
  • Use !! to check truthiness: !!value
  • Be careful with 0 — it’s falsy but often a valid value