I've seen tons of posts about the difference between global and function scope in JavaScript, far too many to link here. I've also seen my exact question asked about Python. So what I want to know is, how can I access a global variable when a "closer" scope also has a variable with the same name?
var a = "global";
function b(){
var a = "local";
var magic = ...; // somehow put "global" in magic
console.log(magic); // should print "global"
}
In browser only, I figured out that you can use window.a
to specify the global. Is there anything that works server-side as well?