Because it makes more sense than NaN which would be the other possible solution.
Number + Text = Text, and the Number is interpreted as the character that compose it in a human reading rather than based on the char matching ASCI or some other table.
The attempt to convert text into numbers to make the operation would give NaN most of the time (Not a Number)… Or should we get the asci value of “1” and get 1+“1” = 50?
I think 1+“1”=11 is a good default, as you see clearly what happend and how to correct it if it is not the result expected…
- BradleyUffner@lemmy.worldEnglish1 day
Then don’t use JavaScript. This functionality is intentionally baked in to the design of the language. It was literally designed to do exactly this. I think it’s dumb too, but my solution isn’t to expect the language to act against its design, it’s to use a strongly typed language.
JackbyDev@programming.devEnglish
1 daydon’t use JavaScript
That’s not really avoidable if your use case is client side scripting in the browser lol.
I don’t really understand how dumb it is to set a wide default type casting. Yet I understand the point of requesting declared casting for some language (when the language is designed to be used by a team of professional dev).
But for languages that aim to be accessible to simple users for personal home pages, with html and css, is it really dumb? May it let mistakes pass without crash the remaining of the script, but it seems acceptable to me in some amateur pages.
If the script is written by a single dev, or a small team, they may decide to only use explicit casting and strict rules for their code…
I think the main mistake is to take javascript for an “easy little language one may use without learn it” just because it is made to be usable by non-professionals. But I could be wrong, and I would gladly understand how wrong I am…
- 1 day
I’m tired of seeing these kinds of titles and critiques about JS.
Stupid questions = stupid answers. That’s all.




