unrust

JavaScript truthiness explorer

Compare Boolean(value), logical OR and nullish coalescing for zero, empty strings, null, undefined, arrays and objects.

Free to use · No sign-up · Inputs stay in your browser

Choose a value

Keep the value in mind. Would you replace it with a default, or preserve what was supplied?

JavaScript value

The fallback is always "fallback". Values come from these built-in examples; no code is uploaded or executed from an input.

Three expressions, side by side

Boolean(0)
false
0 || "fallback"
"fallback"
0 ?? "fallback"
0

Zero is falsy, but it is a present numeric value.

Logical OR replaces this value. Nullish coalescing preserves it.

Practice choosing the right default

An empty label is allowed. Should label || "Untitled" and label ?? "Untitled" be treated as interchangeable?

Check the reasoning

No. An empty string is falsy, so || replaces it. ?? preserves it and substitutes only for null or undefined. Decide whether an empty label is allowed before choosing the operator.

This is an original open example, not a scored drill. Close the tool before taking a diagnostic or an unassisted practice session.

About 14 minutes, no account needed. A free account adds a daily practice queue; paid plans add more practice and the full library.

How to use the result

Pick one of the built-in JavaScript values and compare all three results. The fallback is the string "fallback". This explorer demonstrates truthiness, not loose equality or input validation.

Logical OR (||) chooses its right operand when the left value is falsy. Nullish coalescing (??) chooses it only for null or undefined. With a left value of 0, || returns the fallback and ?? keeps 0.

These utilities and open examples do not contribute to your diagnostic score or practice history.

MDN: nullish coalescing

Work through the example

Keep zero: choosing between || and ?? in JavaScript →