by thetrendycyborg · 14y ago · 0 comments
JavaScript interpreters insert semicolons. If you abuse this, you'll end up with unpredictable results like his function example.
You might not know that the return statement is a restricted production, but you do know when you shouldn't immediately follow it with a linebreak.
Similarly, if you see a line beginning with ( or [ which isn't a continuation of the statement on the previous line, stick a semicolon in front of it, or in the case of a wrapped function() {}, use one of the other means of telling the parser it's a function expression. There are other restricted productions, but you just solved every non return-followed-by-linebreak ASI issue I've ever seen in the wild.
I'd bet with confidence that 90% of programmers out there don't know if a semicolon is needed after a function declaration. They just put it in there blindly, then some day they find a bug because they "forgot" a semi-colon somewhere.
Indenting isn't necessary either. Less necessary even than semicolons. We do it for a reason. Maintainability, understandability.
The less ambiguity the better.
The only advantage you get is you can see a thread like this and say I DON'T USE SEMICOLONS CUZ I BE SO SMART I GET JS SO GOOD. But you're not coding to work with other people. It helps no one else, it's esoteric and unnecessary.