Booleans, Truthy & Falsy in JavaScript
Only eight values are falsy — false, 0, -0, 0n, "", null, undefined, NaN — and everything else (including [] and {}) is truthy. if, while, &&, ||, and ! all coerce through this lens, which makes if (items.length) and value || default idioms work — and makes 0/"" bugs when those are legitimate values.
Double negation (!!) converts to real boolean, Boolean() does it explicitly, and comparisons (>, ===) always produce genuine booleans. Know the eight by heart; every condition you write filters through them.
The falsy eight
false, 0, -0, 0n, "", null, undefined, NaN — memorize the list; literally everything else is truthy.
Empty objects are truthy
[] and {} coerce true — testing emptiness needs .length or key counts, never bare truthiness.
Convert with !!
!!value normalizes any value to its boolean — the standard truthiness probe.
Beware valid zeroes
count || 10 clobbers a legitimate 0 — ?? (nullish) exists precisely for defaulting only null/undefined.
console.log(!!"hi", !!"", !!0, !![]);console.log(0 || "default", 0 ?? "default");Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.