1. The 7 falsy values
Exactly seven values are falsy: false, 0, "", null, undefined, NaN, and 0n. Everything else is truthy.
false, 0, "", null, undefined, NaN, 0nTyporithm · medium
Step 1 of 8 · intro card
JS Gotchas
Exactly seven values are falsy: false, 0, "", null, undefined, NaN, and 0n. Everything else is truthy. Boolean(x) and !!x coerce to a boolean. Watch out: a || b drops valid 0 and "", while a ?? b keeps them.
There are exactly seven falsy values: false, 0, "", null, undefined, NaN, and 0n (the BigInt zero). Every other value — including "0", [], and {} — is truthy.
Boolean(x) returns x's truthiness, and !!x is the idiomatic shorthand: the first ! coerces-and-negates, the second negates back to the real boolean.
The classic pitfall is a || b versus a ?? b: || treats 0 and "" as falsy and replaces them, whereas ?? only replaces null and undefined — so use ?? when 0 or "" are valid inputs.
Seven falsy values: false, 0, "", null, undefined, NaN, 0n.
Boolean(x) and !!x coerce to a boolean.
|| drops 0 and ""; ?? keeps them.
// the 7 falsy values
false, 0, "", null, undefined, NaN, 0n
Boolean("") // false
!!"hi" // true — double-negate to coerce
0 || "x" // "x" — || treats 0 as falsy
0 ?? "x" // 0 — ?? keeps the 0Connect each part of the code to the concept before you type.
Exactly seven values are falsy: false, 0, "", null, undefined, NaN, and 0n. Everything else is truthy.
false, 0, "", null, undefined, NaN, 0nBoolean(x) returns the truthiness of x; an empty string is falsy, so it yields false.
Boolean("") // false!!x is shorthand for Boolean(x): one ! coerces and negates, the second negates back.
!!"hi" // true — double-negate to coerceBecause 0 is falsy, || skips it and returns the right operand, which is a common bug.
0 || "x" // "x" — || treats 0 as falsy?? only replaces null or undefined, so a valid 0 is preserved.
0 ?? "x" // 0 — ?? keeps the 0Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.