ToolMight LogoToolMight

"Guess the Output" JS Trivia Sprint

Test your JavaScript type coercion, hoisting, and scope knowledge in a 60s sprint.

Streak: 0
Score: 0

Ready for the JS Trivia Sprint?

You have 60 seconds to predict what JavaScript snippets log or evaluate to. A single wrong answer breaks your streak and ends the sprint!

Mastering JavaScript Weirdness, Type Coercion & Quirks

JavaScript is famous for counter-intuitive evaluation rules resulting from dynamic typing, implicit type coercion, and legacy ECMAScript design decisions. Understanding these quirks elevates code quality and helps prevent subtle runtime bugs.

1. Implicit Type Coercion Cheat Sheet

Here is how JavaScript handles implicit coercion across common operators:

Addition (+) with Strings: '5' + 3 => "53" (String wins)

Subtraction (-) with Strings: '5' - 3 => 2 (Numeric math forced)

Array Addition: [] + [] => "" (Array to Primitive coercion)

Loose Equality: [] == ![] => true (0 == 0)

2. Variable Hoisting & Temporal Dead Zone (TDZ)

var declarations are hoisted with an initial value of undefined. In contrast, let and const variables are hoisted into a Temporal Dead Zone (TDZ), throwing a ReferenceError if accessed before declaration.

3. Explore More Developer Practice Games

Recreate modern CSS shapes and gradients under the timer in our CSS Speed Challenge, test your reaction times with our Dev Reaction Time Test, or drill speed typing on Speed Typing Test.

Frequently Asked Questions

Why does [] + [] evaluate to an empty string?

Binary + coerces arrays to primitives via ToPrimitive. Converting [] yields an empty string "", resulting in "" + "" = "".

Why is typeof NaN equal to 'number'?

NaN stands for "Not-a-Number", but IEEE 754 floating-point specs classify it as a numeric value representing an undefined calculation.

How does loose equality differ from strict equality?

Loose equality (==) performs type coercion on operands before comparison, whereas strict equality (===) requires matching types and values.