DEV Community

Cover image for Semicolon or No semicolon?

Semicolon or No semicolon?

Sumit Kumar Surana on January 23, 2022

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 insti...
Collapse
 
burtek profile image
Bartosz

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

Collapse
 
bradtaniguchi profile image
Brad

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.

Collapse
 
sayan3990 profile image
Sayan Bhattacharyya

Thanks it is something new to me

Collapse
 
moopet profile image
Ben Sinclair

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

Collapse
 
eljayadobe profile image
Eljay-Adobe

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.

Collapse
 
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.

Collapse
 
rxliuli profile image
rxliuli

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

github.com/rxliuli/liuli-tools/tre...

Collapse
 
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.

Collapse
 
ivan_jrmc 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.

Collapse
 
boyney profile image
Boyne

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

Collapse
 
ethand91 profile image
Ethan

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