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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:30:43+00:00 2026-05-27T00:30:43+00:00

I would like to know what this means: (function () { })(); Is this

  • 0

I would like to know what this means:

(function () {

})();

Is this basically saying document.onload?

  • 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-27T00:30:44+00:00Added an answer on May 27, 2026 at 12:30 am

    It’s an Immediately-Invoked Function Expression, or IIFE for short. It executes immediately after it’s created.

    It has nothing to do with any event-handler for any events (such as document.onload).
    Consider the part within the first pair of parentheses: (function(){})();….it is a regular function expression. Then look at the last pair (function(){})();, this is normally added to an expression to call a function; in this case, our prior expression.

    This pattern is often used when trying to avoid polluting the global namespace, because all the variables used inside the IIFE (like in any other normal function) are not visible outside its scope.
    This is why, maybe, you confused this construction with an event-handler for window.onload, because it’s often used as this:

    (function(){
      // all your code here
      var foo = function() {};
      window.onload = foo;
      // ...
    })();
    // foo is unreachable here (it’s undefined)
    

    Correction suggested by Guffa:

    The function is executed right after it’s created, not after it is parsed. The entire script block is parsed before any code in it is executed. Also, parsing code doesn’t automatically mean that it’s executed, if for example the IIFE is inside a function then it won’t be executed until the function is called.

    Update
    Since this is a pretty popular topic, it’s worth mentioning that IIFE’s can also be written with ES6’s arrow function (like Gajus has pointed out in a comment) :

    ((foo) => {
     // do something with foo here foo
    })('foo value')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know this to understand why some games like Mario is
OK I would like to know this once and for all, how can I
I would like to know whether this is actually possible in Android? When Android
I know this is stupid, but how would I do this? I would like
I know this is a weird question to ask, but I would like to
I would like to know if there are any templates for doing this in
I would like to know how to add menus similar to this to my
Given this algorithm, I would like to know if there exists an iterative version.
In addition to this question: iPhone network performance , I would like to know
This request is based in MS Access VBA. I would like to know what

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.