0

Javascript addition operation is easy to understand if there are only string and numbers or booleans.

But things getting harder with objects and arrays.

I looked into spec ECMA Script 3, 1999 11.6.1 and into Douglas Crockford Enciclopedia but both provided algorithms do not explain why:

[] + {}  // "[object Object]"
{} + []  // 0
{} + 0   // 0
0 + {}   // "0[object Object]"

{} + {}  // NaN, but not either 0 or "[object Object][object Object]"

Is anyone can explain this?

nahab
  • 1,308
  • 17
  • 38

0 Answers0