In a Node.js environment, the global object can be accessed by the
global keyword, while in a browser window it can be accessed by the
window keyword. The
this keyword also refers to the global object when used in the global scope. Please note that using
this in the global scope will return
strict mode is enabled.
// global scope var foo = "bar"; console.log(global.foo); // bar (in a Node environment) console.log(window.foo); // bar (in a browser window) console.log(this.foo); // bar (if strict mode is disabled)
The distinction between scopes local to functions and the global scope is important here: the global object only contains the variables that were declared on the global scope, not the local scopes of functions.
The global object also contains the properties
Infinity and the following functions: