This is how the Addition Operator (+) is defined..
+ operator does not have a "special meaning/overload" for other value types (like arrays) and the behavior in ECMAScript is independent of the behavior in any other language.
The production AdditiveExpression : AdditiveExpression + MultiplicativeExpression is evaluated as follows:
- Let lref be the result of evaluating AdditiveExpression.
- Let lval be GetValue(lref).
- Let rref be the result of evaluating MultiplicativeExpression.
- Let rval be GetValue(rref).
- Let lprim be ToPrimitive(lval).
- Let rprim be ToPrimitive(rval).
- If Type(lprim) is String or Type(rprim) is String, then
Return the String that is the result of concatenating ToString(lprim) followed by ToString(rprim)
- Return the result of applying the addition operation to ToNumber(lprim) and ToNumber(rprim). See the Note below 11.6.3.
The conversion in this case is rather subtle, but is the result of the array values, being Objects without a corresponding primitive type, having "toString" invoked as a result of the
[ToPrimitive] operation. As such the rule application is approximately as follows.
[1,2] + [3,4]
-> [1,2].toString() + [3,4].toString() // Rules #5 and #6
-> "1,2" + "3,4" // Rule #7