News for hackers. Stuff that matters.
Re:JavaScript Is Weird by SCLeo on Monday June 28, 2021 @08:24AM (#27660942)
Probably unpopular opinion: Most of these are just the weirdness of the language caused by the (not-so-wise) design decision that those simple operators should never throw. In my opinion, these are not footguns and should not be used to attack JavaScript, because regular programmers are very unlikely to run into them (which is why when presented, they seem so obscure).

However, that is not to say JavaScript is without footguns. For example, the classic `[1, 2, 3, 10].sort()`.

Re:JavaScript Is Weird by mherrmann on Monday June 28, 2021 @08:27AM (#27660963)
JavaScript sorting numbers alphabetically is a fact I simply cannot get over. I know I should be pragmatic as an engineer but this goes against the core of my being. Awful.
Re:JavaScript Is Weird by epmatsw on Monday June 28, 2021 @08:32AM (#27661024)
Since it’s (imo) default-wrong in English, I’ve chosen to think of it as a nice way to point devs to something that’s locale-aware like Intl.Collator instead. If it “just worked” in English, most of us would never think to use the correct utility instead.
Re:JavaScript Is Weird by mokus on Monday June 28, 2021 @11:14AM (#27662993)
This is a bit of a tangent, but that makes me wonder… are there any languages where this particular collation would be correct?
Re:JavaScript Is Weird by jonny_eh on Monday June 28, 2021 @06:01PM (#27668791)
It also alters the original array, just awful usability.
Re:JavaScript Is Weird by DarkWiiPlayer on Monday June 28, 2021 @09:59AM (#27662044)
Most of these edge cases should result in clear errors. Chances are, if you're adding two arrays somewhere in your application, something else has gone terribly wrong, and just telling the programmer "this makes no sense" would be a much more sensible solution than returning garbage and letting it cause problems somewhere else, further from the real cause of the problem.
Re:JavaScript Is Weird by edgeform on Monday June 28, 2021 @10:13AM (#27662236)
> these are not footguns and should not be used to attack JavaScript

No one is calling them that except you. The site says it right at the front:

> most of this syntax is probably, and hopefully, not something you use in your daily life.

Your obsession with having to choose Side A or Side B won't let you see this for what it is...

Just showing weird syntax in JS. That's all. Good lord.

Re:JavaScript Is Weird by SCLeo on Tuesday June 29, 2021 @04:31AM (#27673321)
I am not choosing a side here.

However, deciding which language to use for a certain task is a legitimate choice that people to make. When making such decision, people need to analysis the pros and cons of a language. For countless times, I have seen people claiming JavaScript is bad/inconsistent/weird for reasons like `"1" + 1 === "11"` but `"1" - 1 === 0`. All I am saying here is things like these should not weigh too much when deciding whether to use JavaScript.

Re:JavaScript Is Weird by zild3d on Monday June 28, 2021 @12:51PM (#27664278)
the title is "javascript is weird", not "here's some weird syntax in javascript"