There surely are strings that can be converted into numbers (even something as simple as “1”). But in general, when languages do implicit conversions, they do it towards the more general type.
For example, if I do 1.1 == 1 in pretty much any language that has separate float and int types, the integer gets casted into a float (from more specific to more general type) and the comparison returns false. It would be utterly ridiculous if the language auto-casts the float to int and then returns true.
JS does just that. Instead of casting the more general number into a string and comparing that, it goes the other way round.
Every number has an equivalent string representation, not every string has an equivalent number representation.
There surely are strings that can be converted into numbers (even something as simple as “1”). But in general, when languages do implicit conversions, they do it towards the more general type.
For example, if I do
1.1 == 1in pretty much any language that has separate float and int types, the integer gets casted into a float (from more specific to more general type) and the comparison returns false. It would be utterly ridiculous if the language auto-casts the float to int and then returns true.JS does just that. Instead of casting the more general number into a string and comparing that, it goes the other way round.
Every number has an equivalent string representation, not every string has an equivalent number representation.