# Truthy and falsy evaluations

*JavaScript Developer Study Guide · Variables, Types, and Collections · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/javascript-developer/variables-types-and-collections/truthy-and-falsy-evaluations*

The eight falsy values and why everything else (including '0', 'false', [] and {}) is truthy; how !, !!, Boolean(), && and || behave and what they return; and when ?? and ?. are the right defaults instead of ||.

- Certification: Salesforce JavaScript Developer
- Exam section: Variables, Types, and Collections
- Study guide: https://www.certifyforce.com/study-guide/javascript-developer

**Official exam objective:**

> Given a specific scenario, distinguish truthy or falsey evaluations.

## What the exam expects

- Name every falsy value and recognise look-alikes that are truthy (`'0'`, `'false'`, `' '`, `[]`, `{}`, `new Boolean(false)`).
- Predict which branch an `if`, ternary or `filter(Boolean)` takes, including when the condition is an accidental assignment.
- Predict the value (not just the truthiness) returned by `&&` and `||`, and convert to a real boolean with `!!` or `Boolean()`.
- Choose `??` over `||` when 0, `''` or `false` are valid values, and use `?.` to read through `null` or `undefined`.
- Explain why `value == true` is not a truthiness test.
- Key terms: **truthy** (treated as `true` in a Boolean context); **falsy** (treated as `false`); **Boolean context** (a place that needs true/false, such as `if`, `while`, `!`, `&&`, `||`, ternary); **short-circuit** (an operator stops evaluating once the result is known); **nullish** (`null` or `undefined`).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Falsy values | `false`, `0`, `-0`, `0n`, `""`, `null`, `undefined`, `NaN` (and `document.all`) | [Falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) |
| `[]`, `{}`, `'0'`, `'false'` | Truthy | [Truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) |
| `new Boolean(false)` | Truthy (an object) | [if...else](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) |
| `!!x` / `Boolean(x)` | Converts to a boolean primitive | [Logical NOT (!)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT) |
| `a \|\| b` | First truthy operand, else the last | [Logical OR (\|\|)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR) |
| `a && b` | First falsy operand, else the last | [Logical AND (&&)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND) |
| `a ?? b` | `b` only if `a` is `null` or `undefined` | [Nullish coalescing operator (??)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing) |
| `obj?.prop` | `undefined` (no throw) when `obj` is nullish | [Optional chaining (?.)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) |
| `if (x = 0)` | Legal; condition is the assigned value 0, so falsy | [Assignment (=)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment) |
| `2 == true` | `false`: `true` becomes 1 | [Equality (==)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality) |
| `arr.filter(Boolean)` | Keeps only truthy elements | [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) |

## Check yourself

- Why does `[0, '0', [], ''].filter(Boolean)` keep `'0'` and `[]`?
- When should you use `??` instead of `||` for a default?
- What does `'admin' && '' && 'user'` evaluate to?
- Why does `if (retriesLeft = 0)` run the `else` branch?
- Which value does `Boolean(new Boolean(false))` return?

## Sources

- [Falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy)
- [Truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy)
- [Logical OR (||)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR)
- [Logical AND (&&)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND)
- [Logical NOT (!)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT)
- [Nullish coalescing operator (??)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing)
- [Optional chaining (?.)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining)
- [if...else](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)
- [Assignment (=)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment)
- [Equality (==)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality)
- [in](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in)
- [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
- [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 10 linked practice questions, and unlimited timed mock exams are included with the JavaScript Developer pack (USD $19): https://www.certifyforce.com/practice-exams
