#4: [] + {}
Topic: coercion · Difficulty: ★★
console.log([] + {});Output
[object Object]
Why
Neither operand is a number or a string, so + converts both to primitives. An empty array becomes the empty string '' (arrays stringify by joining their elements). A plain object becomes the string '[object Object]' — the default Object.prototype.toString result. Concatenating '' with '[object Object]' gives '[object Object]'. The infamous twin, {} + [], prints 0 in some REPLs only because the {} is parsed as an empty block, leaving +[], which is 0.
More coercion puzzles