3 ms·
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
by SCLeo 5y ago
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()`.
- edgeform 5y ago> 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.
- zild3d 5y agothe title is "javascript is weird", not "here's some weird syntax in javascript"
- SCLeo 5y agoI 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.
- mherrmann 5y agoJavaScript 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.
- epmatsw 5y agoSince 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.
- mokus 5y agoThis is a bit of a tangent, but that makes me wonder… are there any languages where this particular collation would be correct?
- jonny_eh 5y agoIt also alters the original array, just awful usability.
- DarkWiiPlayer 5y agoMost 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.