I want to create a quick function that will
console.log(var_name + ": " + eval(var_name));
var foo = "bar";
// ... some stuff happens
console.log('foo: ' + bar);
The reason it doesn't work is because the variable
foo is not accessable to the function
foo is declared in someRandomFunction, and is never passed into
varlog has no idea what the variable foo is! You can solve this problem by passing the variable
foo into the function(or using some sort of closure to make
foo in the scope of
varlog) along with its string representation, but otherwise, I think you are out of luck.
Hope this helps.