Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Why does [] + {} return "[object Object]"?

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]"
Take the full quiz Next question →

More Type Coercion questions

  1. Why does ('b' + 'a' + + 'a' + 'a') return "banana"?
  2. Why does 1 + "2" + "2" return "122"?
  3. Why is false == '0' true in JavaScript?
  4. Why is 3 > 2 > 1 false in JavaScript?
  5. What do true == [] and true == ![] return?

Related topics