Reputation: 16439
I apologize in advance because this is somehow a silly question, but I just need to know WHY this happens and I didn't find the answer. So, there you go, stack overflow!
In this video (which I can't recommend enough) around 2:00 mark the guys shows that in Javascript:
[] + [] = empty string
[] + {} = object
{} + [] = 0
{} + {} = NaN
Anyone knows why?
Upvotes: 7
Views: 1314
Reputation: 1988
This blog post by Adam Iley covers the reasoning behind most of those edge cases.
(Note: The site is having some database problems. You can use the google cache until they fix things.)
Upvotes: 6