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

  • Home
  • SEARCH
  • 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 395187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:25:44+00:00 2026-05-12T16:25:44+00:00

Why does this cause a syntax error for the return statement: var FOO =

  • 0

Why does this cause a syntax error for the return statement:

var FOO = (function($)
{
    return
    {      
        init: function()
        {

        }
    }
})(jQuery);

Whereas this doesn’t:

var FOO = (function($)
{
    return {      
        init: function()
        {

        }
    }
})(jQuery);

Why is there a difference?

  • 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-12T16:25:45+00:00Added an answer on May 12, 2026 at 4:25 pm

    It’s not about the whitespace, it’s about automatic semicolon insertion by JavaScript.

    ECMAScript specification says

    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.

    This means that your code

    var FOO = (function($)
    {
        return
        {      
            init: function()
            {
    
            }
        }
    })(jQuery);
    

    gets translated as

    var FOO = (function($)
    {
        return; // <- JavaScript will insert a semicolon here.
    
        {      
            init: function()
            {
    
            }
        }
    })(jQuery);
    

    So FOO will be undefined after the function is executed.

    For your other code, JS won’t insert any semicolon and it will work correctly JS will insert semicolon after your literal object and it should work fine. [EDIT: Correction as pointed out by kagnax]

    This means that you should always terminate your statements with semicolon. Letting JS engine insert semicolon can introduce very subtle bugs, which would take hours to debug. You can use a tool like JSLint which will warn you of missing semicolons.

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

Sidebar

Ask A Question

Stats

  • Questions 197k
  • Answers 197k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What's going on is that with curl , you are… May 12, 2026 at 7:18 pm
  • Editorial Team
    Editorial Team added an answer Delete from table1 where ID=' ' and Name=' ' and… May 12, 2026 at 7:18 pm
  • Editorial Team
    Editorial Team added an answer This plugin might helps: jquery url parser key = $.url.setUrl($(yourlink).attr('href')).param('key');… May 12, 2026 at 7:18 pm

Related Questions

Here is my sample code. It is meant to be an iterative procedure for
I have never really done much C but am starting to play around with
Lua has a really nice no-parenthesis call syntax that coupled with function closures allow
I've ran against a problem whith git push today. I tried to push a
I am having a problem with Hibernate generating invalid SQL. Specifically, mixing and matching

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.