|
|
|
|
|
by maximusprime
5287 days ago
|
|
No it's not. Logically, the only other thing that could happen is for an "error" or "exception" be thrown when you do '5' - 3
There's really only 2 choices. Either convert the '5' to a number and subtract, or throw a hissy fit because it's a string.That's not perverse. It's very logical. |
|
'5' + 3 - 3 != '5' - 3 + 3
The logical approach would be to only assume that '+' is a string concatenation if both operands are strings and otherwise type coerce into numbers. Then:
'5' + 3 = 8 '5' - 3 = 2
To someone who doesn't code Javascript for a living, the above seems like a far more consistent and useful behavior.