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.

Score0 Streak0 Best0 ♥♥♥
[]truthy or falsy?

Swipe the card, use the buttons, or press ← / → (or F / T).

Do you know your falsy values?

Three lives. A wrong answer or a timeout costs one. The cards get trickier and the clock gets shorter as your score grows.

How to play

  1. Press Start game. A card shows a JavaScript value or a short expression.
  2. Decide what Boolean(value) would return. Swipe the card right (or press → or T) for truthy, left (or ← or F) for falsy.
  3. A correct answer scores points and builds your streak. A wrong answer or a timeout costs a life and shows the explanation.
  4. After three lost lives the game ends and lists the cards you missed, with the reason for each.

Scoring

AnswerEffect
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):

ValueType
falseboolean
0, -0number
0nBigInt
"" (also '' and ``)string
nullnull
undefinedundefined
NaNnumber

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

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.

Related tools