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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:44:23+00:00 2026-06-12T23:44:23+00:00

Javascript closure definition says : A closure is an expression (typically a function) that

  • 0

Javascript closure definition says :

A “closure” is an expression (typically a function) that can have free
variables together with an environment that binds those variables
(that “closes” the expression).

Can some one explain to me the concept of free variables ? Is this concept Javascript specific or applies to other languages also ?

  • 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-12T23:44:24+00:00Added an answer on June 12, 2026 at 11:44 pm

    Free variables are simply the variables that are neither locally declared nor passed as parameter.

    Source :

    In computer programming, the term free variable refers to variables
    used in a function that are not local variables nor parameters of that
    function.1 The term non-local variable is often a synonym in this
    context.

    In javascript closures, those are simply the variables that the function takes (read and write) in the enclosing scope where is declared the closure or in a parent scope.

    Look at this real world example :

    Gol.prototype._ensureInit = function() {
        ...
        var _this = this;
        var setDim = function() {
            _this.w = _this.canvas.clientWidth;
            _this.h = _this.canvas.clientHeight;
            _this.canvas.width = _this.w;
            _this.canvas.height = _this.h;
            _this.dimChanged = true;
            _this.draw();
        };
        setDim();
        window.addEventListener('resize', setDim);
        ...
    };
    

    In this example a closure points from the setDim function towards the variable _this declared in the enclosing scope (the _ensureInit function). This variable isn’t declared in setDim nor passed. It’s a “free variable”.

    Note that _this doesn’t become a variable of the function setDim : another function declared in the same scope would share the same variable.

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

Sidebar

Related Questions

I have a JavaScript file that I ran through the Google Closure compiler, and
I have a JavaScript object that does something like this - using a closure
I have a host javascript closure, in which i keep all the common variables
I'm trying to create javascript closure that will tell me if the function has
I have written some javascript that I would to encapsulate in a closure so
In JavaScript, I know that a closure is can be defined as a nested
The Closure Compiler can use data type information about JavaScript variables to provide enhanced
How can I tell closure compiler that an anonymous function should not be removed
A function in javascript forms a closure by keeping a (hidden) link to its
Possible Duplicate: Javascript Closure Problem In the following code, TrueThis.aChoices[i]['CallBack'] is a function when

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.