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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:40:12+00:00 2026-06-06T04:40:12+00:00

I have seen Javascript code that uses parenthesis immediately after a function’s closing curly

  • 0

I have seen Javascript code that uses parenthesis immediately after a function’s closing curly brace, I can’t understand what they’re used for.

Example:

function foo(bar){
  return bar;
}(0);
  • What does (0) do?

  • What is this called?

  • When should you use this technique?

  • 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-06-06T04:40:13+00:00Added an answer on June 6, 2026 at 4:40 am

    In your example, you simply have two statements and it is equivalent to:

    function foo(bar){
      return bar;
    }
    0;
    

    This is not a self-invoking function. The first statement is a function declaration, the second statement is simply the number literal 0, which does not do anything. The parenthesis don’t execute the function, they are the grouping operator.

    How can we prove this? Try:

    function foo(bar){
      return "bar";
    }(0);
    

    and tell me what the output is.


    It would be a self-invoking function, if we had a function expression. For that you can use the grouping operator to force it being evaluated as expression.

    For example:

    (function foo(bar){
      return bar;
    })(0);
    

    This is a named function expression. The result of the expression ((function ....)) is a function reference, and (0) executes the function, passing 0 as argument.

    The position of the parenthesis could also be:

    (function foo(bar){
      return bar;
    }(0));
    

    Maybe this is what you have seen.

    This technique was already extensively discussed here: What is the purpose of a self executing function in javascript?

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

Sidebar

Related Questions

I have seen Javascript code that claims to speed up function call overhead like:
I have seen and used javascript code that both has and omits the ';'
I have seen in many times in JavaScript code people add a return true
I have a script that uploads an image using JavaScript, as seen here .
I have a Nancy JSON REST service that uses the following serialisation code... FormatterExtensions.AsJson(this.Response,
We have a website that uses javascript, prototype for client scripting, We are starting
I have seen the following methods of putting JavaScript code in an <a> tag:
I have seen facebook javascript api mentioning that loading the sdk asynchronously // Load
It is generally accepted that Javascript code should be wrapped in a function to
I have seen a main() function in some JavaScript files I have come across.

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.