Guess the Console — JavaScript

Guess the console.log output: 15 levels predicting coercion, scope and operator results. A quick-quiz JavaScript fundamentals game for developers.

What you learn in this game

The typeof operator is used to check a value's data type in JavaScript. The result is always a string like "number", "string", "boolean", etc.

The + operator, when used with strings, joins those strings together. A space isn't added automatically: you have to add it yourself.

Type coercion happens when JavaScript automatically changes a data type. If the + operator meets one string, all operands are turned into strings and joined.

JavaScript has two comparison operators: == (loose equality) does type coercion, while === (strict equality) doesn't. With ==, "1" and 1 are considered equal.

In JavaScript, some values are considered "falsy" (they evaluate to false): false, 0, "", null, undefined, NaN. All other values are "truthy".

A template literal uses backticks (`) and can insert JavaScript expressions inside ${...}. Easier than ordinary concatenation.

What the levels ask

  1. What will appear in the console?
  2. What will appear in the console?
  3. What will appear in the console?
  4. What will appear in the console?
  5. What will appear in the console?
  6. What will appear in the console?
  7. What will appear in the console?
  8. What will appear in the console?
  9. What will appear in the console?
  10. What will appear in the console?
  11. What will appear in the console?
  12. What will appear in the console?

And more, 22 levels in all.