1035
JavaScript (lemmy.ml)
you are viewing a single comment's thread
view the rest of the comments
[-] palordrolap@fedia.io 19 points 1 week ago

it commutes

Maybe the behaviour with regard to type conversion, but not for the operation itself.

"13"+12 and 12+"13" don't yield the same result.

[-] raspberriesareyummy@lemmy.world 8 points 1 week ago

Nor would I expect "1312" to equal "1213".. Still that operator with these operands should just throw an exception

[-] palordrolap@fedia.io 4 points 1 week ago

Given it's JavaScript, which was expressly designed to carry on regardless, I could see an argument for it returning NaN, (or silently doing what Perl does, like I mention in a different comment) but then there'd have to be an entirely different way of concatenating strings.

[-] raspberriesareyummy@lemmy.world 5 points 1 week ago

Why would you need an entirely different way of concatenating strings? "11" + 1 -> exception. "11" + to_string(1) = "111"

[-] palordrolap@fedia.io 2 points 1 week ago

You're right. I've got too much Perl on the brain and forgot my roots. There is a language that does what you're talking about with the '+' operator: BASIC

Good luck getting the same thing retrofitted into JavaScript though. I can imagine a large number of websites would break or develop mysterious problems if this (mis)behaviour was fixed.

[-] raspberriesareyummy@lemmy.world 1 points 6 days ago

I don't think there's a way to retrofit JS - but php versions are deprecated all the time. Why not do the same with client-side script versions? :)

load more comments (2 replies)
load more comments (2 replies)
load more comments (2 replies)
this post was submitted on 04 Jun 2025
1035 points (98.6% liked)

Programmer Humor

24079 readers
984 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS