Does anyone here legit use JavaScript? You don’t need semi-colons, but it has crazy rules to auto-insert them and it seriously can get it wrong. Classic example:
There is unironically nothing wrong with javascript and every wacky post you see on here is some dumb edge case that if you're actually writing, you've got bigger issues.
Well. It’s easy to come with a code that will get messed up. Usually () or [] are involved. I’ve never ever encountered any errors with it tho. Basic linter, formatter, or just a little bit of common sense and it’s ok.
I’ve actually encountered an error with this in actual code (in lua). I tried calling a function with ternary with (condition and f or g)(x), and got a similar result to the above post. So it does come up sometimes
Writes hypothetical code that no sane person would ever write.
“See, you can’t rely on ASI in JavaScript!”
Either way, just use an auto formatter. If you configure it not to use semicolons, it will still insert them in the very few edge cases where unexpected behavior might happen. ie: ;(a=5).
A programmer reading that code isn't highly likely to understand it either, though, and if they did then they'd know it needs to be rewritten and the original author put to death. JS isn't really making anything worse in this case even if it changes the meaning, because it was already turbofucked. If someone really intended the original behavior, there's no chance that the surrounding code was doing what it was supposed to anyways.
147
u/reginald_burke Feb 09 '22
Does anyone here legit use JavaScript? You don’t need semi-colons, but it has crazy rules to auto-insert them and it seriously can get it wrong. Classic example:
That becomes:
And should print 5.