|
|
|
|
|
by Nadya
3919 days ago
|
|
>'+' is string concatenation but '-' is interpret these strings as numbers and perform arithmetic? That's precisely it. You cannot subtract a string so it coerces "5" and "4" to integers instead of treating them as strings. So it results in 5 - 4. The first concatenates two strings, "5" and "1" and results in "51". It's perfectly reasonable behavior. If you want to add numbers you should give it integers - namely 5 and 1 instead of two strings "5" and "1". The unreasonable behavior is giving integers as strings. |
|
I get what you're saying literally, I strongly disagree that it is reasonable, at all. If you can't subtract them, there should be an error at that point, telling the programmer it can't be done.