Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In the JavaScript world, tread cautiously on this passionate topic. https://github.com/twbs/bootstrap/issues/3057


I'm not going to lie, my blood pressure went up just from skimming that thread. Boy howdy, I don't miss any aspect of JS development, its ecosystem or community.

I just ran across this "JS semicolon topic" again recently while reading Next.js documentation in order to help a colleague debug an issue they were facing. AFAICT, that project's documentation doesn't have a single semicolon anywhere in it. (They're using `const` everywhere, tho! ) What are the odds someone has copied code from those docs and run into a quirk around _automatic semicolon insertion_? They're not zero! I mean, it's simple, you just have to remember that a newline ends a statement ... except when:

> The statement has an unclosed paren, array literal, or object literal or ends in some other way that is not a valid way to end a statement. (For instance, ending with . or ,.) > The line is -- or ++ (in which case it will decrement/increment the next token.) > It is a for(), while(), do, if(), or else, and there is no { > The next line starts with [, (, +, *, /, -, ,, ., or some other binary operator that can only be found between two tokens in a single expression.

(^ From https://eslint.style/rules/js/semi)

Stop being cute and just use semicolons.


> Stop being cute and just use semicolons. Or stop being cute and let ASI insert the semicolon for you. ;) I haven’t used a trailing semicolon in probably ten years.

Btw Douglas Crawford’s comments there didn’t age well. He’s wrong on every count (jsmin should follow JS semi rules, semi-less won’t break in the future, it’s only more popular than ever, etc) and just comes off as hot headed and “anyone who likes X is stupid but not me.”


> I haven’t used a trailing semicolon in probably ten years.

I haven't used my seat belt in ten years and bangs roof I'm doing just fine!


This makes no sense unless you're unaware of tools like Prettier and eslint which are the seatbelt in your analogy (we don't need analogies, please).

These tools have changed the argument into one over aesthetics which is why opponents have had to grasp for increasingly hypothetical scenarios where the sky falls because the code doesn't use semicolons. Even in the github thread, it starts off concern-trolling over hypothetical day 1 beginners copy-pasting code into Notepad.

That github thread was back in 2012 btw (12 years ago) which was the year of the final throes of the semicolon debate. None of the chicken littling came true. People still upset about semicolons are like that Japanese soldier still hiding in the Philippines in the 1970s thinking WW2 is raging, except they refuse to admit it's just a style preference.


I am putting semicolons on the altar in the church of JavaScript so that one particularly difficult day linter will say: "index.js, line 235, character 17: missing closing bracket".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: