Why does {} + [] return 0 in Javascript?

Viewed 6034

Possible Duplicate:
What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?

I know that when [] is coerced to a string it returns the empty string (""), and when {} is coerced to a string it returns "[object Object]".

When I run [] + {} in my browser's Javascript console, it returns as I would expect:

>> [] + {}
"[object Object]"

But when I run {} + [], it returns a completely unexpected value:

>> {} + []
0

What could be causing it to return 0?

3 Answers
Related