tl;dr: Always use semicolons
This is the worst trend in modern JS IMO. There’s no reason not to use semi-colons in this language.
A E S T H E T I C
And always use brackets around statement blocks. I have no idea why so many people think that they are being clever by eliminating basic syntax.
“It’s fewer characters therefore it’s simple and lightweight” - the same reason I see justifying React hooks. You still have an object, you still have a stand-in for “this”, but now it’s secret and hidden from the application programmer in ambient library magic, and therefore your code is somehow “functional” despite being full of mutable state.
because it feels alright to omit them when you’re writing the statements for the first time because the context is fresh in your memory
If you liked that check out what this snippet of code prints:
n = 1
/1*"\/\//.test(n + '"//')
The explanation is left as an exercise for the reader.
The problem with these solutions is they don’t suppose that code files are concatenated. Semicolons on statements beginning with the characters [ or ( should always start with a semicolon in this case.
This debate will never end. For good measure, some arguments against semicolons.
I’m sorry, but that article is almost comedy. The author suggests to work around problems that the lack of statement terminating semicolons causes, one should prepend a semicolon to lines that begin with a parenthesis, bracket, or arithmetic operator.
;(d + e).print()
What?!? is that passing code review anywhere? Sometimes doing something because everybody else is doing it is in fact a valid reason.
Fun test: remove all ; from your current codebase, and see if that breaks any test.