It can be difficult to determine what "all the variables" are if you use anything global. By default, global variables all fall under the window
scope. So you could loop over all values in window
, but that would give you everything else as well.
If you put everything inside of a namespace, you can be more explicit about it.
var MyVariables = {
};
MyVariables.foo = 1;
MyVariables.hello = 'world';
for(var name in MyVariables){
console.log(name, MyVariables[name]);
}
Also check out the dev tools available on your browser. I personally would recommend Chrome Dev tools (builtin, F12), or FireBug in FireFox. IE does have some built-ins as well.