Why does it do this? So confuuuusing.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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"+6is"Hi6", and"Hi6"+10is"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".