When a beginner asks you "when do I use semi-colons?" would you rather say this?
// what people who say "use semicolons!!" say
class Foo {
prop = {
}; // yes
static bar () {
if (stuff) {
doStuff(); // yes
} // no
for (var key in obj) {
} // no
return {
}; // yes
} // no
foo () {
} // no
} // no
Foo.prop = {
}; // yes
things.map(thing => thing.name /*no*/)
var boing = function () {
}; // yes
function boing () {
} // no
/*no*/[1,2,3].map(); // yes
/*no*/(function () {})(); // yes
Or this?
// what people who say "don't use semicolons!" say
/*yes*/;[1,2,3].map()
/*yes*/;(function () {})()
// which are two things I haven't done in the last 3 years, mind you
In the end, I'd rather not talk about semi-colons, and just do what people around me want me to do, but when teaching a beginner who asks (and they ALWAYS ask this) "when do I use a semi-colon", I just put my face in my hands and say "I don't have any answers for you".
There are some really edge cases where a missing semicolon will break things.
Regarding template literals in ES6, which only applies if the template literal is preceded by an identifier:
This is riddled with Things You Shouldn't Do™ like:
Also, arithmetic operators:
Which again, are things you would never want to do in the first place. In practice, semicolons are easier to omit than they are to include.
I wrote more about this subject here. The tl;dr is don't treat JS as if it had significant newlines but rather we should strive to understand ASI, and understanding ASI is easier to grok when you think about when you should add semicolons rather than when you should omit them.