Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Getting a Handle on the DOM Using CSS Queries to Select Page Elements

Declaring JavaScript variables in the Chrome console for debug purposes: Where do they go?

When declaring a JavaScript variable in the Chrome console (e.g., for debug purposes), where is this variable stored?

For example, let's say I made a mistake when declaring the variable, and I want to find it so I can revise or delete the declaration. Is this possible?

PS. I know I can just refresh my browser to erase any variables that I created in the console, but I'm curious :)

1 Answer

Stuart Wright
Stuart Wright
41,120 Points

Variables declared in the console are added to the window object (https://developer.mozilla.org/en-US/docs/Web/API/Window).

Try:

var my_variable = "hi";

Then type:

window;

Click on the arrow to expand the window object, scroll through the properties and you should see that my_variable now exists as a property of the window object.