My understanding is that:
For
[] + []
and[] + {}
, the+
operator is interpreted as string concatenation, values coerced to strings, so the expressions evaluate to""
and"[object Object]"
.For
{} + {}
, different browser engines interpret it as either string concatenation or addition, so the results vary ("[object Object][object Object]"
in Chrome orNaN
in Firefox).
Why does {} + []
evaluate to 0
?
My line of thinking is that +
is interpreted as addition, so {}
should be coerced to NaN
and []
to 0
. Then why doesn't the above expression evaluate to NaN + 0
i.e. NaN
?