|
|
|
|
|
by uhryks
2462 days ago
|
|
Why not? It's not entirely explicit but it seems that the `++` operator is only for string concatenation, so using it with anything else that a string means it's going to be converted to string.
I'm just curious about how the compiler enforces it. |
|
If + is to be defined on a string and a number then the only sensible meaning is string concatenation. All numbers can be converted to strings but most strings cannot be converted to numbers.
There is a good reason to not define it because it is not associative: in JavaScript 2+2+"x" != 2+(2+"x")