Global Object#
What Is The Global Object?#
- A global object is an object that always exists in the global scope. In JavaScript, there's always a global object defined. In a web browser, when scripts create global variables defined with the var keyword, they're created as members of the global object. (In NodeJs this is not the case.)
- We used this
console.logfunction to log something on the console. Now thisconsole objectis what we call aglobal object. So its part of theglobalscope which means we can access it anywhere, in any files.
| app.js | |
|---|---|
1 2 | |
- We have a bunch of other objects and functions that are also globally available in Node.
- In Node when we try to define global variables with
varkeyword, they are not assigned into the global scope they are only a scope to the current js file (Ex: app.js) and not available out side of it. And this is because of Node's modular system.