Truthy or Falsy? The JavaScript Swipe Game
A JavaScript value appears on a card. Is it truthy or falsy? Swipe left for falsy, right for truthy, before the clock runs out. It starts easy with 0 and "", then moves on to the coercion puzzles that catch out experienced developers. Every wrong answer comes with the reason.
[]truthy or falsy?Swipe the card, use the buttons, or press ← / → (or F / T).
How to play
- Press Start game. A card shows a JavaScript value or a short expression.
- Decide what
Boolean(value)would return. Swipe the card right (or press → or T) for truthy, left (or ← or F) for falsy. - A correct answer scores points and builds your streak. A wrong answer or a timeout costs a life and shows the explanation.
- After three lost lives the game ends and lists the cards you missed, with the reason for each.
Scoring
| Answer | Effect |
|---|---|
| Correct | +10 points, ×2 from a streak of 5, ×3 from 10, ×4 from 15 |
| Wrong | −1 life, streak back to 0 |
| Too slow | −1 life; the time per card shrinks from 5 to 2 seconds as you score |
The complete list of falsy values
JavaScript has only a handful of falsy values. Everything else, including every object and every non-empty string, is truthy (MDN: Falsy):
| Value | Type |
|---|---|
false | boolean |
0, -0 | number |
0n | BigInt |
"" (also '' and ``) | string |
null | null |
undefined | undefined |
NaN | number |
The odd one out is document.all, a legacy browser object that is deliberately falsy for old-site compatibility. It does not appear in the game.
The traps that cost the most lives
- Empty containers are truthy.
[]and{}are objects, soif ([])runs. Checkarr.lengthorObject.keys(obj).lengthinstead. - Strings are judged by length, not content.
"0","false"and" "are all truthy. - Loose equality is not truthiness.
[] == falseistrue, yet[]itself is truthy. The==operator converts both sides to numbers first. ||and??differ.0 || 5is 5 because 0 is falsy, while0 ?? 5is 0 because??only replacesnullandundefined.
When you are unsure about a value in real code, paste it into the browser console as Boolean(value) or !!value. To see what an API really returns, the JSON Formatter shows it with its types.
Frequently asked questions
What does truthy mean in JavaScript?
A truthy value is one that counts as true when JavaScript needs a boolean, for example in an if condition or with !, && and ||. Every value is truthy except the falsy ones listed above.
Is an empty array truthy or falsy?
Truthy. An empty array is an object, and all objects are truthy. Use array.length === 0 to test for an empty array.
Are the answers in the game correct?
Each card’s answer was checked by running Boolean() on the expression in a JavaScript engine, so they match what Chrome, Firefox, Safari and Node.js return.
Is the game free?
Yes. It runs in your browser with no sign-up, and your best score is saved only in this browser.