Skip to content

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.log function to log something on the console. Now this console object is what we call a global object. So its part of the global scope which means we can access it anywhere, in any files.
app.js
1
2
var message = "text message!";
console.log(message); //global.console.log(message)
  • 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 var keyword, 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.

See Also#

References#