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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:53:04+00:00 2026-05-31T09:53:04+00:00

I started reading this: http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth And they refer to anonymous closure: This is the

  • 0

I started reading this: http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth

And they refer to anonymous closure:

This is the fundamental construct that makes it all possible, and
really is the single best feature of JavaScript. We’ll simply create
an anonymous function, and execute it immediately. All of the code
that runs inside the function lives in a closure, which provides
privacy and state throughout the lifetime of our application.

(function () {
    // ... all vars and functions are in this scope only
    // still maintains access to all globals
}());
  • I don’t understand what happens in a self-executing anonymous
    function closure-wise, that is different from a normal closure and
    why is it so special?
  • What is the benefit in it?
  • 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-31T09:53:05+00:00Added an answer on May 31, 2026 at 9:53 am

    Variables that are not defined within a closure get into the window variable and are global.

    Example:

    var SOME_CONSTANT = 4;
    
    function foo() { 
        var c = SOME_CONSTANT;
        console.log( c );
    }
    
    foo();
    

    If you have this code, SOME_CONSTANT will be global to all files and code run within inline scripts etc, which may not be desired.

    You can use the self-calling closure to keep the variable only inside this closure:

    ( function() {
        var SOME_CONSTANT = 4;
    
        function foo() {
            var c = SOME_CONSTANT;
            console.log( c );
        }
    
        foo();
    
    } () );
    

    This way you can have modules that have variables global only to that module. For example, by having the code of each file enclosed in such an anonymous function.

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

Sidebar

Related Questions

So I started reading this book: http://www.amazon.com/Cocoa-Design-Patterns-Erik-Buck/dp/0321535022 On chapter 2 it explains about the
I am reading this: http://www.panoramio.com/api/widget/api.html#photo-widget to build a JavaScript photo widget. Under Request ->
I want to learn multiprocessing in python. I started reading http://www.doughellmann.com/PyMOTW/multiprocessing/basics.html and I am
I was reading this document: http://www.fadden.com/techmisc/hdc/lesson11.htm In it he stated: Problem is, we don't
I am reading this tutorial : http://sleekd.com/general/adding-multiple-images-to-a-rails-model-with-paperclip/ because i need Save the product images
Forgive if this question is silly. I just started reading the SugarCRM developer documentation
I started reading about underscore.js today, it is a library for javascript that adds
I just started reading on Douglas Crockford's Javascript The Good parts where he explains
I'm reading this nice tutorial about Node.js web servers: http://nodebeginner.org/ In this part of
I want to improve performance of my app, and started reading http://guides.rubyonrails.org/performance_testing.html . My

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.