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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:26:20+00:00 2026-05-26T11:26:20+00:00

Before actually asking anything, I’ll go ahead and say this is a theoretical question;

  • 0

Before actually asking anything, I’ll go ahead and say this is a theoretical question; however, it might be implemented on a website later on.

Anyway, I have a variable, any variable. Let’s say it’s a and its scope is global. Now, for a specific function, I want to set that variable’s value to something other than it’s global value, but based on it, and without changing its value globally. For example:

a = {something: "Safe", other: "Foo"}
function hello(){
  var a = a.other; // Foo
  a.something; // Undefined
}
a.something; // Safe
a.other; // Foo

The issue with the above code is that when I define var a in the function, it will have already cleared the value of the global a locally before setting it; in other words, it would return something like Can't access property [other] of undefined [a].

Again, a should still be a (so using another variable name is not an option, or at least not the ideal one). In fact, the global a should not be accessible from the function hello.

Edit: window will also be overwritten with null, regarding Milan Jaric’s answer.

Thanks in advance!

  • 1 1 Answer
  • 1 View
  • 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-26T11:26:21+00:00Added an answer on May 26, 2026 at 11:26 am

    This is what I was looking for…now, before you think I had the answer before I asked, I didn’t, I was only able to reach a tangible solution based on Milan Jaric’s answer (thanks btw).

    a = {something: "Safe", other: "Foo"}
    function hello(b){
      var window = null;
      var a = b; // a.other;
      a.something; // Undefined
    }
    a.something // Safe
    a.other // Foo
    
    hello(a.other)
    

    (I never really said what could or couldn’t go outside the function).

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

Sidebar

Related Questions

I actually asked this question before, but I cannot get my account details back,
I realise this question has been asking before, but I've yet to find an
I actually asked this question in a different form before. I did get a
Before I describe my problem, it might actually make it clearer if I start
Before answering, it is not as easy question as you might have thought about
This question has been asked before, but I would like a little more detail
(I can't believe I'm actually asking this, but I am out of brainpower for
I am imagining that this might get me dinged for asking such a non-specific
Simplified the question to give a more clear representation of what I'm actually asking
I need to test if a user can write to a folder before actually

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.