11
submitted 4 days ago* (last edited 4 days ago) by codeinabox@programming.dev to c/javascript@programming.dev
all 8 comments
sorted by: hot top new old
[-] peacepath@lemmy.world 4 points 3 days ago

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…

[-] alsimoneau@lemmy.ca 13 points 3 days ago

I expect a TypeError.

Return a value at any cost is a mistake

[-] BradleyUffner@lemmy.world 1 points 3 days ago

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.dev 3 points 3 days ago

don't use JavaScript

That's not really avoidable if your use case is client side scripting in the browser lol.

[-] peacepath@lemmy.world 3 points 3 days ago

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…

[-] slazer2au@lemmy.world 4 points 4 days ago
[-] KaKi87@jlai.lu 0 points 3 days ago

I'm tired of seeing these kinds of titles and critiques about JS.

Stupid questions = stupid answers. That's all.

this post was submitted on 22 Aug 2026
11 points (92.3% liked)

JavaScript

2784 readers
1 users here now

founded 3 years ago
MODERATORS