3 ms·
When are semicolons to be avoided in JS? I assume daft styleguides pushed by people desperate to show how smart they are don't count. I agree with your broade
by maw 10y ago
When are semicolons to be avoided in JS? I assume daft styleguides pushed by people desperate to show how smart they are don't count.
I agree with your broader point, of course; certainly making them optional hasn't helped matters.
- sli 10y agoI don't know of a single instance where it's advised to omit a semicolon, nor one where a semicolon is strictly required. They are always optional. About all I've seen is Standard's guideline to put a semicolon before your entry point closure: ;(function() { // .. snip })() And even that isn't required, it's just a function of another guideline: "Never start a line with (, [, or `." But still, that is only relevant to Standard, not to Javascript in general. It's completely self-enforced by deciding to use Standard if you want. I can't remember ever needing to put one of those characters at the start of a line outside that particular instance, anyway.
- maw 10y agoI think the reason was to work around too simplistic minifiers and concatenators.
- smt88 10y ago> daft styleguides Daft is correct, but some of them are being pushed by large companies and (frustratingly) seem to be somewhat adopted.