Fundamentalsbeginner

Truthy and Falsy Values

The short, memorizable list of values JavaScript treats as false in a boolean context, and everything else.

Every value in JavaScript has an inherent boolean nature when it shows up somewhere a boolean is expected, like an if condition, a while loop, or the operands of && and ||. Rather than being an obscure detail, this is used constantly in idiomatic JS for validation and default values, so interviewers expect a crisp answer on exactly which values are falsy.

Falsy values are like a very short guest list of six people not allowed into the 'true' party — everyone else in the world, no matter how unusual, gets in automatically.

Key Concepts

1
There are only six falsy values in JavaScript (technically seven with document.all, which is a legacy special case): false, 0 (and -0), '' (empty string), null, undefined, and NaN. Every other value is truthy, which surprises people the first time they learn that '0' (a non-empty string containing the character zero), [] (an empty array), and {} (an empty object) are all truthy, because they are objects or non-empty strings even though they 'feel' empty or zero-like.
document.allfalse0-0''
2
This truthy/falsy system underlies several idiomatic patterns. The logical OR || is often used to supply a default value (const name = input || 'Guest'), though this misfires if a legitimate falsy value like 0 or '' is a valid input — which is exactly why the nullish coalescing operator ?? was introduced, since it only falls back on null/undefined rather than every falsy value. Similarly, && is used for conditional rendering or execution (isLoggedIn && renderDashboard()), short-circuiting before evaluating the right side if the left side is falsy.
||const name = input || 'Guest'0''??
3
Getting comfortable with this list means you can read conditional expressions quickly and, more importantly, know when || is the wrong tool and ?? or an explicit comparison (=== undefined) is needed instead.
||??=== undefined