Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 23, 2022 05:20 pm GMT

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 wont spend too much time explaining about it since it is really well articulated in ecma specs https://tc39.es/ecma262/#sec-automatic-semicolon-insertion.

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 https://tc39.es/ecma262/#sec-asi-interesting-cases-in-statement-lists.

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.

Consistency

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 https://davidwalsh.name/javascript-semicolons.


Original Link: https://dev.to/ssurana2/semicolon-or-no-semicolon-2d7h

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To