Understanding the JavaScript Global Object Across Different Environments
Every JavaScript runtime has a special global object that provides built-in features such as setTimeout, Math, Date, console, and JSON. In web browsers, this global object is referred to as window, meaning window.Math and Math point to the same value. In server-side environments like Node.js, the global object is called global, while in web workers it is known as self. To address this inconsistency across environments, JavaScript introduced globalThis as a universal reference to the global object. Regardless of the runtime, globalThis always resolves to the correct global object, whether that is window, global, or self.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in