Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding empty object and array

Tags:

javascript

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?

like image 483
Pere Villega Avatar asked Jan 27 '12 19:01

Pere Villega


1 Answers

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.)

like image 93
seth.miller Avatar answered Oct 06 '22 01:10

seth.miller