3 ms·
What really keeps me up at night is wondering about the semicolon after a class definition: class Foo { ... };
by bigyikes 6y ago
What really keeps me up at night is wondering about the semicolon after a class definition:
class Foo {
...
};
- regularfry 6y agoThis doesn't get one. It's confusing, but explicit in the ecmascript spec. That form of class definition is called a ClassDeclaration, and they don't take semicolons. I haven't checked, but I think what you've typed here is valid because the parser sees a zero-length expression after the '}'. The reason it's confusing is because if you modify it very slightly, then the semicolon becomes required: let Bar = class Foo { ... }; In that context, precisely the same sequence of characters as you had before is now called a ClassExpression, and the semicolon isn't attached to the class, but instead to the preceding let. I do find semicolons useful as an indicator at the end of the class expression that there's a let or a const somewhere above, but it's far simpler to just not do that and pretend that language facility doesn't exist unless you really, really need it.