Frontend Engineering
JavaScript Deep Dive
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
Question 2: Order Matters
console.log({} + []);
Quiz
Question 3: The Null Surprise
console.log(null == 0);
console.log(null > 0);
console.log(null >= 0);
Quiz
Question 4: Boolean Traps
console.log(true + true + true);
console.log(true == 1);
console.log(true === 1);
Quiz
Question 5: String Number Dance
console.log("5" - 3);
console.log("5" + 3);
console.log("5" - - "3");
Quiz
Question 6: Array Coercion Chain
console.log([1] == true);
console.log([0] == false);
console.log([""] == false);
Quiz
Question 7: The typeof Chain
console.log(typeof typeof 42);
Quiz
Question 8: The Grand Finale
console.log([] + [] + "foo".split(""));
Quiz
Scoring Guide
| Score | Assessment |
|---|---|
| 8/8 | You can trace coercion algorithms from memory. Exceptional. |
| 6-7 | Solid understanding with minor gaps. Review the cases you missed. |
| 4-5 | You know the basics but the algorithm details are fuzzy. Revisit ToPrimitive and the == steps. |
| 0-3 | Go back to the types and coercion lesson. Focus on the step-by-step algorithm, not memorizing results. |