4.3 The global object

The global object is an object whose properties become global variables. (We’ll examine soon how exactly it fits into the tree of environments.) It can be accessed via the following global variables:

  • Available on all platforms: globalThis. The name is based on the fact that it has the same value as this in global scope.
  • Other variables for the global object are not available on all platforms:
    • window is the classic way of referring to the global object. It works in normal browser code, but not in Web Workers (processes running concurrently to the normal browser process) and not on Node.js.
    • self is available everywhere in browsers (including in Web Workers). But it isn’t supported by Node.js.
    • global is only available on Node.js.