3 ms·
In JavaScript (and in TypeScript), not using the semi-colon is often a footgun. Here's a surprise: const a = 1 const b = 2 (a+b).toString() Calling the
by jeswin 3y ago
In JavaScript (and in TypeScript), not using the semi-colon is often a footgun.
Here's a surprise:
const a = 1
const b = 2
(a+b).toString()
Calling the convention "standard" was irresponsible, and it led many people (especially beginners) to assume that it was some sort of a preferred convention. Glad I'm seeing it less these days; thanks to TypeScript, and people following Microsoft's conventions.
- WorldMaker 3y agoThere's only one "extra" rule to remember when not using semicolons: the winky frown rule. If it starts with a frown (, [, ` then it must wink: ;(, ;[, ;` It's a silly sounding rule, but that makes it easy to remember. The rest of Automatic Semicolon Insertion footguns happen to everyone whether they use semicolons or not, such as: do not add a newline after return, that makes it a return undefined. Semicolons won't help. (Typescript return type annotations will help.) Related to the topic at hand, prettier configured with `{ "semi": false }` (which I prefer to standard these days because I think prettier autoformatting is, uh, prettier) in my experience catches most winky frown violations for you and auto-fixes them.