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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:42:33+00:00 2026-05-26T00:42:33+00:00

Possible Duplicate: Is there a difference between (function() {…}()); and (function() {…})();? I’ve seen

  • 0

Possible Duplicate:
Is there a difference between (function() {…}()); and (function() {…})();?

I’ve seen the following syntax used to prevent variables from getting into global scope:

(function ($, undefined)
{

})(jQuery);

More recently I’ve seen code doing it this way:

(function ($, undefined)
{

} (jQuery));

I find the 1st way makes the most sense to me. I mentally read it as:

I’ve defined a function and I wish to wrap it into an expression, (the first set of parenthesis). That expression is a function object which I then wish to call using method syntax and the parameter I’m passing to this function object is jQuery.

The 2nd syntax is less clear to me, because it looks like the outer parenthesis are unnecessary.

My javascript knowledge isn’t quite good enough yet to feel comfortable w/ the 2nd syntax.
Do these produce identical behavior? Is there any difference at all?

What would happen if you did this?

function ($, undefined)
{

} (jQuery);
  • 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-26T00:42:33+00:00Added an answer on May 26, 2026 at 12:42 am

    If a function keyword occurs at the start of a line it is parsed as a function statement declaration. Funcsion statements require a function name so the 3rd option you present is not allowed (you can test that yourself).

    If the function keyword appears elsewhere it is parsed as a function expression and is allowed to be anonymous. There are many ways to do this but the convention for the module pattern you shown is wraping the construct in parenthesis. (Some byte-savers like using a unary operator like + or ~ instead)

    If you choose to use the parenthesis puting the last one inside (1st version) or outside (2nd version) is a matter of personal preference. I prefer the 2nd one since the parenthesis wraps the whole pattern instead of just the function.

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

Sidebar

Related Questions

Possible Duplicate: what is the function __construct used for? is there any difference between
Possible Duplicate: Difference between try-catch syntax for function What is the difference in the
Possible Duplicate: C++: What's the difference between function(myVar) and (function)myVar ? I have seen
Possible Duplicate: Difference between (function(){})(); and function(){}(); I have seen it a lot by
Possible Duplicate: Is there a performance difference between BETWEEN and IN with MySQL or
Possible Duplicate: String vs string in C# I know there is no difference between
Possible Duplicate: C#: Difference between ‘ += anEvent’ and ‘ += new EventHandler(anEvent)’ There
Possible Duplicate: c#: difference between “System.Object” and “object” Hello, In C# there are Object
Possible Duplicate: are there function pointers in c#? I'm interested in finding the difference
Possible Duplicate: Is there a performance difference between i++ and ++i in C++? In

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.