Priority and associativity of operators.
Two points:
- The
+ operator concatenates strings if one or both arguments are strings. - The
+ operator works from left to right.
So, in your example, "Hi"+6 is "Hi6" , and "Hi6"+10 is "Hi610" .
EDIT: as you say in the comment to another answer: if the numbers are the first, then the numeric addition is performed first, because the leftmost two operands are numbers. Then only at the end does the string concatenate. Thus, we get "16Hi" .
source share