← All concepts
Fundamentals: Part 2

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);        // false

These 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 truthy

The 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

Practice this

Further reading