Advanced
JavaScript
Q100 / 100
What is the JavaScript type coercion for addition with objects?
Correct! Well done.
Incorrect.
The correct answer is B) Objects are converted to primitives via valueOf() or toString(); {} + [] returns 0 because {} is parsed as an empty block in statement position
B
Correct Answer
Objects are converted to primitives via valueOf() or toString(); {} + [] returns 0 because {} is parsed as an empty block in statement position
Explanation
({}) + [] = "[object Object]" when {} is an expression. At statement level, {} is a block and + [] = 0. This is one of JavaScript's most confusing coercion behaviors.
Progress
100/100