[Solved] Why does the addition (plus) operator produce a string when the left operand is a number and the right one is a string? [duplicate]


Because the spec says so. See The Addition operator (+):

  1. If Type(lprim) is String or Type(rprim) is String, then
    1. Return the String that is the result of concatenating ToString(lprim) followed by ToString(rprim)
  2. Return the result of applying the addition operation to ToNumber(lprim) and ToNumber(rprim).

So it only matters whether some operand is a string, but not which one.

solved Why does the addition (plus) operator produce a string when the left operand is a number and the right one is a string? [duplicate]