I am learning JavaScript and have been doing a lot of testing in the Chrome console. Even if I clear the console, or use any of the commands I\'ve seen in other threads (
What you are affecting when declaring any variables or functions within the developer console is the global execution context, which for web browsers is window.
When you clear() the console you are telling Chrome to remove all visible history of these operations, not clear the objects that you have attached to window
.
To do this you must manually delete
each object by its reference:
delete name;
name //=> undefined
If the overhead of having to repeatedly remove multiple objects via delete
is too much, store each value as a property of an object, e.g. data
, that you can delete along with all properties in one statement:
var data = {};
data.name = 'Bob';
data.age = 60;
delete data;
data.name //=> ReferenceError: data is not defined
data.age //=> ReferenceError: data is not defined