← 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.

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.

Common mistakes

  • Treating `"0"` or an empty array `[]` as falsy because they look empty; only the eight exact falsy values coerce to false.
  • Using `value || fallback` for a default and accidentally discarding a real `0` or empty string.
  • Forgetting that `NaN` is falsy, so a failed numeric check can be mistaken for a valid falsy business value.

Key takeaways

  • Only `false`, `0`, `-0`, `0n`, `""`, `null`, `undefined`, and `NaN` are falsy; everything else is truthy.
  • Arrays and objects are always truthy, even when empty.
  • Use `??` instead of `||` when `0` or `""` should count as a valid value.
Check your understanding

Which of these values is truthy?

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.

Practice this

Further reading

Previous
let, const, var, and the Temporal Dead Zone
Next
Hoisting