Tips for using window in JavaScript
In web browsers, window refers to an object that contains the global variables. This blog post explains how it works and when to use it. The global object and window The ECMAScript specification uses the internal data structure environment to store variables. The language has the somewhat unusual feature of making the environment for global variables accessible as an object, the so-called global object . The global object can be used to create, read and change global variables. In global scope, this points to it: > var foo = 'hello'; > this.foo // read global variable 'hello' > this.bar = 'world'; // create global variable > bar 'world' In web browsers, the global variable window also points to the global object. JavaScript creator Brendan Eich considers the global object one of his “ biggest regrets ”. Cross-platform considerations Node.js does not have a global variable window . Therefore, the only safe cross-p...