"2" +
2 - 2 = ?
The answer is surprising, and different in
each of the following languages:
- Perl
- The answer is 2. Strings convert to numbers, then the
rest is arithmetic
-
- Javascript
- The answer is 20! The type conversion rules for plus turn
the first operation into a string concatenation to get the
string "22". Then the type conversion rules for
minus convert this to a number and subtract.
|