Falsy values
Values that become false in boolean context. The list is small and should be memorized.
Truthy and falsy describe how values behave when JavaScript needs a boolean, such as inside if, while, &&, || or !.
if ("0") {
console.log("This runs because non-empty strings are truthy.");
}
if (0) {
console.log("This does not run.");
}
Values & Types
JavaScript does not require every condition to be true or false already. It converts values to boolean in conditional contexts.
Only a small list of values is falsy: false, 0, -0, 0n, an empty string, null, undefined, NaN and the browser legacy object document.all. Everything else is truthy.
This is convenient, but it can hide bugs. An empty array is truthy. An empty object is truthy. The string "false" is truthy because it is not empty.
Values that become false in boolean context. The list is small and should be memorized.
All values not on the falsy list, including [], {}, "0" and "false".
A clear way to convert a value to true or false.
Useful, but only when you mean all falsy values are invalid.
Examples
const itemCount = 0;
if (itemCount !== null && itemCount !== undefined) {
console.log(`Items selected: ${itemCount}`);
}
const itemCount = 0;
if (!itemCount) {
console.log("No item count provided");
}
// But 0 may be a real value.
Rules that matter
JavaScript lets values move flexibly, but professional code keeps meaning clear. Convert at boundaries, validate input and choose values that represent the real idea.
There are few falsy values; everything else is truthy.
{} and [] are truthy.
If 0 is meaningful, do not reject it with !value.
Boolean(value) makes conversion obvious.
Use || only when all falsy values should fallback.
isOpen, hasPaid and canSubmit should already read like true or false.
Production thinking
Truthy and falsy rules explain why JavaScript conditions sometimes feel surprising. Once you know the list, the surprises become predictable.
Form validation often uses truthy/falsy checks. Bad checks can reject legitimate answers or hide important feedback.
Production validation should distinguish empty, missing, zero and false when those states mean different things.
Falsy rendering mistakes can accidentally hide valid content such as count 0, rating 0 or empty but meaningful labels.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Say the answer in plain language. If you can explain the value behavior, the code becomes much easier to debug.