Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6133147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:11:25+00:00 2026-05-23T17:11:25+00:00

I tend to be a prolific user of semicolons in my JavaScript: var x

  • 0

I tend to be a prolific user of semicolons in my JavaScript:

var x = 1;
var y = 2;
if (x==y){do something};

I recently noticed that I was looking at a lot of JavaScript that doesn’t have semicolons following if statements. It then occurred to me that I don’t even know the preferred syntax for semicolons in JS and after some googling learned (rather surprisingly) that there is no need for semicolons at all aside from splitting statements that are on one line.

So, the question…where did this habit of people using semicolons come from? Is it a remnant from some popular language that was in use at the time JavaScript came into play? Just good practice in general? Is it just me?

I’m probably going to stick with it for no other reason that it’s nice when writing jQuery chains to easily spot the end.

UPDATE:

Thanks for all the answers, everyone! It looks like, to summarize things, the reason we see a lot of semicolons in JS even when not needed comes from various variables:

  • older JS minimizer’s would produce broken code if you did not insert semicolons
  • many other languages use them, so it’s a carried-over habit
  • on occasion, a semicolon CAN change the logic
  • some prefer to use them to make the code more human-readable
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:11:27+00:00Added an answer on May 23, 2026 at 5:11 pm

    Many computer languages use semicolons to denote the end of a statement. C, C++, and Java are popular examples of this.

    As for why people use them despite them being optional, they improve the readability of your code. In most cases it’s simply done out of habit, but occasionally you need semicolons in your code to remove possible ambiguity. It’s always better safe (and consistent) than sorry.

    Here is an example taken from Do you recommend using semicolons after every statement in JavaScript?

    // define a function
    var fn = function () {
        //...
    } // semicolon missing at this line
    
    // then execute some code inside a closure
    (function () {
        //...
    })();
    

    This will be interpreted as:

    var fn = function () {
        //...
    }(function () {
        //...
    })();
    

    Additionally, semicolons allow Javascript to be packed/minified properly. Otherwise all the statements will be mushed together into one big mess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always tend to run into the following design problem that I'm never quite
my stylesheets tend to have a lot of redundancy. for example, /* example one:
I tend to use the following pattern a lot of different places for a
One of the reasons that I tend to dread writing Javascript for anything other
I have noted over the years, that I tend to write maybe a screen
I tend to write code like the following a lot: BufferedWriter w = null;
We mostly tend to following the above best practice. Have a look at String
I have read a lot of topic here and people tend to store IP
I tend to use a lot of jquery ajax calls to the server side
It seems I tend to attract strange issues. This time, I have written a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.