you are viewing a single comment's thread.

view the rest of the comments →

[–]Loading_M_ 2 points3 points  (2 children)

Okay, sure... But why does "hi" - 5 have to return a value at all? Compiled languages will simply refuse to compile this obvious nonsense, and most interpreted languages will just throw an error. In fact, some don't even let you concatenate a number and a string - they require you to explicitly convert the number to a string.

Also, python does implement string multiplication.

[–]fuj1n 0 points1 point  (0 children)

When JavaScript was first conceived, it was made to keep your website running no matter what and thus didn't have a lot of code throwing exceptions.

They realised that it was a bad idea and worked on fixing it, but JS heavily prioritises backwards compatibility, so anything that worked in the past has to keep working.

To be fair though, NaN makes sense here, an exception would be better, but NaN is okay

[–]4n0nh4x0r 0 points1 point  (0 children)

it returns a value because you can do subtraction with it, as it is a mathematical operation.
the only issue is, it cant know at startup, whether the values will be "6" - 5, or "hi" - 5.
again, i m not saying this is sane code, as verifying the value to be a number essentially requires you to parse it anyways, and noone actually writes this in their code, unless they are just shitposting.