Nathan Firth

  • Archive
  • RSS

JavaScript Weirdness

I was just listening to the lightning talk by Gary Bernhardt from CodeMash 2012 and he brought up some really interesting (and funny) points about JavaScript.

For example:

[] + []; 

””

{} + {};

NaN

[] + {};

[object Object]

{} + []; 

0

So why is it that if you add two empty Arrays you get an empty string, but if you add two objects you get “not a number”. Array + Object is an Object but Object plus Array is 0???

    • #javascript
    • #weirdness
  • 3 weeks ago
  • 1
  • Permalink
  • Share
    Tweet

About

I'm an internet entrepreneur, web developer, designer, lover of Jesus from San Diego. Originally from Sweden. I have a beautiful wife, and two amazing kids.
Follow @nathanfirth

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco but customized by Nathan Firth.

Powered by Tumblr