Skip to content

Quiz: Predict the Output — Coercion

intermediate7 min read

Test Your Type Coercion Intuition

Each question below involves JavaScript's type coercion rules. Don't just guess — trace the algorithm step by step using the Abstract Equality algorithm, ToPrimitive, ToNumber, and ToBoolean rules from the types and coercion lesson.

If you get fewer than 6 out of 8, revisit the coercion lesson. If you get all 8, you're in the top 1% of JavaScript developers on this topic.


Question 1: The Classic

console.log([] + {});
Quiz
What does [] + {} output?

Question 2: Order Matters

console.log({} + []);
Quiz
What does {} + [] output in the browser console?

Question 3: The Null Surprise

console.log(null == 0);
console.log(null > 0);
console.log(null >= 0);
Quiz
What are the three results?

Question 4: Boolean Traps

console.log(true + true + true);
console.log(true == 1);
console.log(true === 1);
Quiz
What are the three results?

Question 5: String Number Dance

console.log("5" - 3);
console.log("5" + 3);
console.log("5" - - "3");
Quiz
What are the three results?

Question 6: Array Coercion Chain

console.log([1] == true);
console.log([0] == false);
console.log([""] == false);
Quiz
What are the three results?

Question 7: The typeof Chain

console.log(typeof typeof 42);
Quiz
What does typeof typeof 42 return?

Question 8: The Grand Finale

console.log([] + [] + "foo".split(""));
Quiz
What is the output?

Scoring Guide

ScoreAssessment
8/8You can trace coercion algorithms from memory. Exceptional.
6-7Solid understanding with minor gaps. Review the cases you missed.
4-5You know the basics but the algorithm details are fuzzy. Revisit ToPrimitive and the == steps.
0-3Go back to the types and coercion lesson. Focus on the step-by-step algorithm, not memorizing results.