-
Notifications
You must be signed in to change notification settings - Fork 2
JS Global Object
The global object is an object that is initialised by the JavaScript interpreter before the code is executed. All variables that are declared on the global scope (see: Scopes) are stored in the global object as properties.
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 undefined
if strict mode
is enabled.
For example:
// 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 NaN
, undefined
and Infinity
and the following functions:
decodeURI()
decodeURIComponent()
encodeURI()
encodeURIComponent()
escape()
eval()
GetObject()
isFinite()
isNaN()
parseFloat()
parseInt()
ScriptEngine()
ScriptEngineBuildVersion()
ScriptEngineMajorVersion()
ScriptEngineMinorVersion()
unescape()
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links