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

razmig pulurian
PLUS
razmig pulurian
Courses Plus Student 23,888 Points

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,091 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.