Can anyone explain this behavior?
This answer attempts to explain this behavior in terms of specification.
According to spec , during time evaluation, +both expressions (left and right) are converted to their primitive values.
- Let lprim be ToPrimitive (lval).
- Let rprim be ToPrimitive (rval).
toPrimitive tries to pass hint:number(after the call during arithmetic evaluation) to OrdinaryToPrimitive
- "", . methodNames "toString", "valueOf" ".
- Else,
. methodNames " "valueOf", "toString" ".//
, 4a) , .
[1,2,4] + 1 = > [1,2,4].toString() + "1" = > "1,2,4" + "1" = > () "1,2,41"