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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:10:29+00:00 2026-05-26T01:10:29+00:00

I am learning javascript and I came across the following code snippet: var outerValue

  • 0

I am learning javascript and I came across the following code snippet:

var outerValue = true;

function outerFn(){
  assert( outerFn && outerValue, "These come from the closure." );
}

Insofar as I understand closures in the above context, they allow the outerFn to actually see the outerValue variable.

My question then is: how is this any different from any other programming language – such as java for instance? It is just expected that outerValue’s scope will allow outerFn to see it.

added later on:

    var outerValue = true;
    function outerFn() {
        console.log(outerValue);
    }

    function anotherFunction(arg){
        console.log("anotherFunction");
        arg.call(this);
    }

    anotherFunction(outerFn); 

Is this then a better example of a closure?

  • 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-26T01:10:30+00:00Added an answer on May 26, 2026 at 1:10 am

    Your example does not really illustrate the difference, as you do not define the scope of outerValue. In Javascript, you may nest functions arbitrarily within one another, and closures make sure that inner functions can see outer functions even when invoked after the outer functions are no longer in scope.

    In java, nesting functions is not (yet) legal, and thus closures do not even come into play. Having a class field in place of outerValue and a class method in place of your function is different, as the field of course is associated with the scope of the class, not the method.

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

Sidebar

Related Questions

I'm actively learning javascript, and I came across the following statement: Object.prototype.toString.call([]); And I
I am learning javascript and can someone please explain the following code snippet for
I m reading John Resig s Learning Advanced JavaScript http://ejohn.org/apps/learn/#10 and came across this
I was toying (read: learning) around with Javascript and came across something to my
Learning javascript when I came across the concept of prototype. I succeeded in adding
Learning about OAuth, I came across a big question. How to call a JavaScript
I'm learning javascript. Poked around this excellent site to gather intel. Keep coming across
I'm learning python using the tutorial on the official python website and came across
I'm a newbie learning Javascript. In the following tutorial, I don`t understand why value
I've been reading up on the Prototype source code while learning Javascript. I've been

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.