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 6794483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:13:39+00:00 2026-05-26T18:13:39+00:00

I want to know, is this legal? function test() { alert (hello) $(#loading).show(); }

  • 0

I want to know, is this legal?

function test()
{
    alert ("hello")
    $("#loading").show();
}

Or should I write this instead:

function test()
{
    alert ("hello");
    $("#loading").show();
}

Are semicolons optional in JavaScript? Because I saw this in a forum:

No, semicolons are usually optional in JavaScript (Google for ASI / automatic semicolon insertion). Using them makes the code look much cleaner though and ASI is a horrible mis-feature (at least in my opinion).

  • 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-26T18:13:40+00:00Added an answer on May 26, 2026 at 6:13 pm

    Semicolons are not always mandatory, but I would always recommend using them. See the ECMAScript spec for the rules on automatic semicolon insertion:

    Certain ECMAScript statements (empty statement, variable statement,
    expression statement, do-while statement, continue statement, break
    statement, return statement, and throw statement) must be terminated
    with semicolons. Such semicolons may always appear explicitly in the
    source text. For convenience, however, such semicolons may be omitted
    from the source text in certain situations. These situations are
    described by saying that semicolons are automatically inserted into
    the source code token stream in those situations.

    Update (to explain further)

    Perhaps the most common situation used to show why automatic semicolon insertion can be bad is that touched on by @sissonb in another answer. Consider the following:

    function something(a, b) {
        return
        a + b;
    }
    

    What you may be expecting is for the new-line to be ignored, and the code interpreted as:

    function something(a, b) {
        return a + b;
    }
    

    Unfortunately, automatic semicolon insertion comes into play, and the code is actually interpreted like this:

    function something(a, b) {
        return;
        a + b;
    }
    

    And an empty return statement means the function returns undefined. So instead of a nice sum of the two argument, you get undefined and potentially end up very confused as to where you’ve gone wrong! Which is why I completely agree with the statement in your question that automatic semicolon insertion is a horrible misfeature.

    • Example (returns undefined because of ASI).
    • Example (returns expected result).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know this more in detail. Is it a realtime scheduler? An
I want to know what this looks like. I don't have any ideas about
I want to know if this web app are using long polling or anything
Ok, I know how to do this, but I want to know if this
I know this question isn't directly programming related, but since I want to be
I know this question is probably stoopid. But I just don't want to cause
I know there is this post , but I still want to know more
i want to import in my iphone application, but i know this framework is
The title is kind of obscure. What I want to know is if this
i just want to know a general information about this particular information. Any good

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.