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

  • Home
  • SEARCH
  • 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 8258943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:43:16+00:00 2026-06-08T02:43:16+00:00

Are global variables stored in specific object? For instance: var test=stuff; console.log(window.test); console.log(document.test); console.log(this.test);

  • 0

Are global variables stored in specific object? For instance:

var test="stuff";
console.log(window.test);
console.log(document.test);
console.log(this.test);

All three of these tests result in undefined, so is there an object that holds these variables?

I feel as though this is something stupid that I should already know, but I can’t even seem to find the answer online.

  • 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-08T02:43:19+00:00Added an answer on June 8, 2026 at 2:43 am

    I think you’ll find on most browsers, they are stored in window.

    Far-fetched psychic debugging attempt: did you test this in jsFiddle? Or perhaps in Firebug? If so, you’re probably seeing undefined for all three because in that case the code is executed in a frame; so it has a different window object (I think) the code is actually wrapped:

    window.addEvent('load', function() {
      var test="stuff";
      console.log(window.test);
      console.log(document.test);
      console.log(this.test);
    });
    

    You can see from the above snippet from jsFiddle that test is not a global variable, which explains why it hasn’t been attached to window.

    I’m no expert, but this answer appears to be accurate from what I can tell in Chrome, Firefox, Safari, and Opera. To verify, I created an HTML file with the following content and loaded it in each browser:

    <script type="text/javascript">
      var test = "stuff";
      alert(window.test);
    </script>
    

    Sure enough, “stuff” every time.

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

Sidebar

Related Questions

I have list view and its adapter stored as global variables. I am not
I always hear using global variables are dangerous. Does this apply to Drupal? Take
I'm using global variables to pass around a response from a AJAX call: window.response
Where are pointers and global variables stored in C ? Are they saved in
If I have a list of global variables like this... int a; char b;
Every global variable in javascript is a property of 'window' Apparently all local variable
Usually, the static and global variables are both stored in the .data or .bss
In a Windows device driver: per-driver information is stored in global variables per-device information
Possible Duplicate: Where are static variables stored (in C/C++)? I am wondering where global
I stored global variables in my AppDelegate and access them by: AppDelegate *d =

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.