Learn JavaScript
❯ types.truthy_falsy

Booleans, Truthy & Falsy in JavaScript

$concept

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.

$how it works
1

The falsy eight

false, 0, -0, 0n, "", null, undefined, NaN — memorize the list; literally everything else is truthy.

2

Empty objects are truthy

[] and {} coerce true — testing emptiness needs .length or key counts, never bare truthiness.

3

Convert with !!

!!value normalizes any value to its boolean — the standard truthiness probe.

4

Beware valid zeroes

count || 10 clobbers a legitimate 0 — ?? (nullish) exists precisely for defaulting only null/undefined.

$example
console.log(!!"hi", !!"", !!0, !![]);
console.log(0 || "default", 0 ?? "default");
Output
true false false true
default 0
1"hi" truthy, "" and 0 falsy, [] truthy despite emptiness — the eight in action.
2|| falls through falsy 0 to default, while ?? keeps 0 (only null/undefined fall through).
3The contrast is the whole lesson: || defaults broadly, ?? defaults narrowly.
$use cases
Guard clauses (if (!input) return) that read as plain intent
Defaulting with ?? instead of || when 0/"" are valid
Emptiness checks via .length, never bare [] truthiness
Normalizing flags with !! at API boundaries

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.