Truthy and Falsy Values
Every value is truthy unless it is one of a short, memorizable list of falsy values.
Loading visual…
Definition
In a boolean context, such as an `if` condition or the `!` operator, JavaScript coerces any value to `true` or `false`. There are only eight falsy values: `false`, `0`, `-0`, `0n`, `""` (empty string), `null`, `undefined`, and `NaN`. Every other value is truthy, including values that might feel empty or negative, like `"0"` (a non-empty string), an empty array `[]`, and an empty object `{}`, because arrays and objects are always truthy regardless of what they contain. This rule powers common patterns like `if (value)` as a shorthand null/empty check, `value || fallback` for defaults, and `!!value` to force a value into an explicit boolean. It is also a common source of bugs: `value || fallback` treats a legitimate `0` or `""` as missing, which is why the nullish coalescing operator `??` (which only falls back on `null`/`undefined`) is often the safer choice.
Examples
Boolean(0); // false
Boolean(""); // false
Boolean(null); // false
Boolean(undefined); // false
Boolean(NaN); // falseThese are five of the eight falsy values; false, -0, and 0n round out the full list.
Boolean("0"); // true, a non-empty string
Boolean([]); // true, an array is always truthy
Boolean({}); // true, an object is always truthyThe string "0" and empty containers are common gotchas: they look empty but coerce to true because only the eight exact falsy values coerce to false.
const count = 0;
const shown = count || "no items"; // "no items", a bug: 0 was meaningful
const safe = count ?? "no items"; // 0, correct: only null/undefined fall back|| falls back on any falsy value, so a real 0 gets discarded; ?? only falls back on null or undefined, preserving 0 as a valid value.
Where you see this
- Writing guard clauses like if (!user) return; to short-circuit on null, undefined, or empty values.
- Using !!value to coerce an arbitrary value into an explicit true/false for a UI flag.
- Debugging a default value that silently overrides a legitimate 0 or empty string because || was used instead of ??.
- Checking array.length (truthy when non-zero, falsy when 0) instead of the array itself, which is always truthy.