Skip to content

Falsy

Easy — everyone uses thisFrontend

ELI5 — The Vibe Check

Falsy values are the six (well, seven) values in JavaScript that evaluate to false in a boolean context: false, 0, empty string, null, undefined, and NaN. Plus -0 and 0n if you're counting. Everything else is truthy. The classic bug: checking if (count) when count is 0 — it's falsy even though 0 is a perfectly valid number.

Real Talk

Falsy values in JavaScript are values that coerce to false in boolean contexts. The complete list: false, 0, -0, 0n (BigInt zero), '' (empty string), null, undefined, and NaN. Common bugs arise from falsy checks on valid zero values or empty strings. The nullish coalescing operator (??) was introduced specifically to distinguish null/undefined from other falsy values.

Show Me The Code

// All falsy values
Boolean(false)     // false
Boolean(0)         // false
Boolean('')        // false
Boolean(null)      // false
Boolean(undefined) // false
Boolean(NaN)       // false

// The classic bug:
const items = 0
if (items) { /* never runs, even though 0 items is valid */ }
if (items != null) { /* correct way to check */ }

When You'll Hear This

"Zero is falsy — that's why the counter disappears when it hits 0." / "Use strict equality (===) to avoid falsy surprises."

Made with passive-aggressive love by manoga.digital. Powered by Claude.