DEV Community

Cover image for Semicolon or No semicolon?
Sumit Kumar Surana
Sumit Kumar Surana

Posted on

Semicolon or No semicolon?

I have 10 years of experience being a JavaScript developer and I forget that semicolon is optional. Adding a semicolon in the end is a simple instinct for me.

From my point of view, if you are using the right tools like jshint or jslint to catch the syntax errors before pushing the code to your repository, it doesn't matter if you use a semicolon or not.

I use semicolons in the end because I am tuned that way while working with professionals or mentors who end the statement with a semicolon. I also advocate using semicolons in the end because of the following reasons.

Automatic semicolon assertion

I won’t spend too much time explaining about it since it is really well articulated in ecma specs

To put it simply, it is better to handle the semicolon ourselves than relying on a compiler/minifier which has a chance of being unpredictable. Especially, when you are using ‘[‘ or ‘(‘ or binary operator or a regex in the next line without ending the previous statement with a semicolon. Refer

I prefer lesser risk on my production code and I believe in the statement that if something can go wrong it will definitely go wrong.


Most developers nowadays are full stack developers who have dabbled in one or more backend languages. And most of the popular backend languages (apart from python that I know of) have statements ending with semicolon.

So when a developer tends to switch between other programming languages and JavaScript they don't have to unlearn the idea of not putting the semicolon in the end. Remember it is optional. So no offense if someone puts it or omits it. But the idea is to keep a single standard and consistency so that it doesn't cause any confusion among team members on what to follow. So make sure you choose one or else brace yourself for resolving lots of ideology clashes among the team members like the discussion going on at

Discussion (14)

burtek profile image

There are cases where a semi is always required, i.e.

const data = fn1();
(await fn2()).something
Enter fullscreen mode Exit fullscreen mode

I prefer using semis always rather than having to use them as exception, which IMO break the code style

bradtaniguchi profile image

My usual stance on this is whatever my auto-formatter adds automatically.

Prettier has an option to toggle this behavior on and off.

Few argue about spacing in code because it's usually automatically added/removed via tooling. As long as it's consistent within the codebase it usually isn't an area of contention.

I believe semi-colons should be in the same boat. Just let the computer add/remove/apply them. The few edge-cases should be handled by other tooling, like TypeScript.

sayan3990 profile image
Sayan Bhattacharyya

Thanks it is something new to me

eljayadobe profile image

I use Standard JS. q.v. my other post reply.

In an Edna Mode voice, "No semicolons!"

Josh Perez No, you don't need semicolons. And when a semicolon is necessary, I use Max Bendick Semicolons go at the beginning of the line.

wafflook profile image
Yusuke Sano • Edited on

Somewhere along the line, I stopped using the semicolon. Most of the time, it works correctly without it.


Enter fullscreen mode Exit fullscreen mode

My question to web developers is about the position of the closing tag in HTML: when HTML is auto-formatted, the first character '<' of the start tag is aligned above the slash of the end tag. I don't like this.
Having the element name aligned above the element name is clean HTML to me.


Enter fullscreen mode Exit fullscreen mode
moopet profile image
Ben Sinclair

Auto-formatted by what? I've never seen auto-formatting do that before.

alaindet profile image
Alain D'Ettorre

I advise to always use them.

I know that Python and JavaScript are the most popular ones and it's cheap to skip them, but since most languages use them anyway, it's better to use them for me. Besides, I think the code is a bit clearer with semicolons.

rxliuli profile image

It's not what format that matters, it's just one format, for that matter, I configure the npm package with a custom prettier preset

bcowley1220 profile image
Brendan Cowley

Nope, stopped using em a while ago and never looked back. Fecking linters put them back in anyways so who cares.

ivanjeremic profile image
Ivan Jeremic

I think they exist because there was a time without syntax highlighting and you need to see where the end is.

boyney profile image

I mean you can put semicolons in Python if you want everyone to hate you

ethand91 profile image

I always use semicolons. Got so used to it that I have to keep reminding myself to stop using them in a language like python... xD