Do you know what will be the output of this code?
JavaScript
console.log([] + {});
Show answer and explanation
The + operator converts both operands to primitives first. Neither an array nor a plain object is a primitive, so JavaScript calls their toString() methods:
[].toString() // => ""
({}).toString() // => "[object Object]"
Since one of the operands is now a string, + does string concatenation instead of addition:
"" + "[object Object]"
=> "[object Object]"