Skip to content
Browse files

Add article on the global object

  • Loading branch information...
1 parent f3d1e44 commit 6b7d930d07d9102736b08c1a3e84c229a30cb38e @awesomeaniruddh awesomeaniruddh committed
Showing with 42 additions and 0 deletions.
  1. +42 −0 js-Global-Object.md
View
42 js-Global-Object.md
@@ -0,0 +1,42 @@
+# The 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](js-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:
+
+```js
+// 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:
+
+1. `decodeURI()`
+2. `decodeURIComponent()`
+3. `encodeURI()`
+4. `encodeURIComponent()`
+5. `escape()`
+6. `eval()`
+7. `GetObject()`
+8. `isFinite()`
+9. `isNaN()`
+10. `parseFloat()`
+11. `parseInt()`
+12. `ScriptEngine()`
+13. `ScriptEngineBuildVersion()`
+14. `ScriptEngineMajorVersion()`
+15. `ScriptEngineMinorVersion()`
+16. `unescape()`
+
+# References
+
+1. MSDN: [Global Object (Javascript)](https://msdn.microsoft.com/en-us/library/52f50e9t(v=vs.94).aspx)

0 comments on commit 6b7d930

Please sign in to comment.
Something went wrong with that request. Please try again.