Apples contains 3, and oranges contains 5.
Expression | Result |
---|---|
apples + oranges | 8 |
"total is " + apples + oranges | "total is 35" |
The solution is simply to use parentheses to force the numeric part of the expression to be evaluated first.
Expression | Result |
---|---|
"total is " + (apples + oranges) | "total is 8" |
|