Why does it do this? So confuuuusing.
Operator precedence and associativity.
Two points:
+ does string concatenation if one or both arguments are Strings.+ works from left to right.So in your example, "Hi"+6 is "Hi6", and "Hi6"+10 is "Hi610".
EDIT: As you say in a comment to another answer: If the numbers are first, then a numeric addition is done first, because the leftmost two operands are numbers. Then, only at the end, a string concatenation occurs. So that yields "16Hi".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With