Asked • 06/06/19

Is window really global in Javascript?

Take this piece of Javascript in a browser: <script> console.log(window.someThing); var x = 12; function foo() { window.otherThing = x; } </script>Inside `foo` we can access `window`, we all know that, but why exactly?- Is it some kind of special global variable?- Or does the "root scope" (inside the `script` tag) have it as an implicit local variable and is it simply "closure-inherited" as any other local variable (like `x` above) can be?And how does that concur with variables declared directly inside the `script` tag being set as properties of `window`? (Or is that not so?) <script> var x = 12; function() { console.log(window.x); } </script>

1 Expert Answer


Sparky E. answered • 07/08/19

Computer Science Major, CTO at CollabTrade

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.