|
|
|
|
|
by maximusprime
5287 days ago
|
|
See my comment below. It's not about being trapped in any mindset. It's about thinking logically. Either '5' - 3 results in an error of some kind, or it evaluates to 2. There is no other logical outcome. Javascript chooses to do the latter. I also disagree that starting language matters. It's like saying you need to have a steinway grand to learn the piano properly. Learning is about learning what not to do just as much, if not more, than what to do. Also if you learn to swim through syrup, imagine how fast you'll be when you try swimming through water... |
|
* '5' - 3 should return '5', since it's the string '5' minus all the instances of the character '3' in it. There is no other logical outcome!
* '5' - 3 should return an empty string, since it's the string '5' with the last three characters removed. There is no other logical outcome!
* '5' - 3 should return '2' -- since we started with a string, the result should turn back into a string. There is no other logical outcome!
* '5' - 3 should return 50, since the only logical way to do math on a character is to take the UTF-8/ASCII value of it and then do the math. There is no other logical outcome!
* '5' - 3 should return undefined, since subtracting from a string typically doesn't produce a reasonable result. There is no other logical outcome!
You have provided absolutely no rational basis for discriminating between the merits of these choices, so your claim that Javascript's choice is one of exactly two "logical" ones is bizarre. If you think Javascript's choice is better, give a reason why it's better, don't just say that it's better.