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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:07:27+00:00 2026-06-01T04:07:27+00:00

I heard today that: it is possible to access a local variable of a

  • 0

I heard today that:

it is possible to access a local variable of a function since everything in JavaScript is global.

As far as I know, you can’t access a local variable from outside of the scope of the variable.

For example:

function f()
{
    var myvar = "something";
}

myvar = "c"; // i'm not accessing myvar in f();

I also heard that it’s possible to use for(var i in window) to access myvar. I want to confirm it is not possible since I’m not the author of the language.

Updated:

I asked him a code snippet, and here’s what I have received.

var person = {
    whoIs : function()
    {
        var name = "name";
        return name;
    }
};


var str = "TEST:\n";

for(var n in person)
{
    str += n;
    str += " = [" + person[n] + "]\n";
}

// perform regular exp. to get the value of name variable.


alert(str);

It’s not accessing the variable.. it’s simply printing how the function looks like…

  • 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-01T04:07:28+00:00Added an answer on June 1, 2026 at 4:07 am

    That developer was wrong. Those two myvar are different. The outside one is equivalent to window.myvar, but the inside one is only inside the f.

    Edit: a very simple example: http://jsfiddle.net/mRkX3/

    Edit 2:

    A quote from the ECMAScript standard:

    If the variable statement occurs inside a FunctionDeclaration, the variables are defined with function-local scope in that function, as described in section 10.1.3. Otherwise, they are defined with global scope (that is, they are created as members of the global object, as described in section 10.1.3) using property attributes { DontDelete }. Variables are created when the execution scope is entered. A Block does not define a new execution scope. Only Program and FunctionDeclaration produce a new scope. Variables are initialised to undefined when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created.

    Found through http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting though that article is referencing a deadlink (live link: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf).

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

Sidebar

Related Questions

Today I heard from my colleague that search bot can index pages with sequential
I heard today that Maxima can do the country plot by contour_plot in Sage.
I work in an asp.net shop, and I heard today that the bottleneck on
Today, I heard of Karatsuba algorithm, a fast multiplication algorithm. I am curious that
I know this question may well be the silliest question you've heard today, but
I heard that it's possible to identify the brand of a device (or at
I know reference counter technique but never heard of mark-sweep technique until today, when
Does anyone know of a plugin or something that can be used to send
I have heard that C doesn't have closure, and today I saw the use
I'm very interested in search engines. Today in a talk I heard that google

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.