So I know that you could previously access any variable using the variable name in a string form via the window
object, like this:
variable = "test";
alert(window["variable"]); // Alerts "test"
And that works.
But when you do this, it doesn't work:
var variable = "test";
alert(window["variable"]); // Alerts undefined
- Why does the only difference, the
var
, cause it to returnundefined
? - Is this a recent change to JavaScript?
- Is there a way around it? If so, what?
Also, please note that I am using version 55.0.2883.87 m of Chrome.
Thanks!