JavaScript globalThis Property
globalThis refers to the global object in any JavaScript environment, whether that is window in a browser, self in a worker or global in Node.js.
Description
The globalThis property gives access to the global object in a way that works everywhere. Before it existed, code had to check for window, self or global depending on where it ran. Global variables declared with var and global functions become its properties; let, const and class declarations do not.
In a module or strict-mode function, top-level this is undefined, so globalThis is the reliable way to reach the global object in any context. It's mostly used by libraries that run in several environments, and for feature checks such as 'IntersectionObserver' in globalThis.
Adding your own properties to the global object is best avoided, because every script on the page shares it and names can clash. Modules with exports are the modern way to share values between scripts.
Syntax
globalThisValue
The global object: window in browsers, self in workers and global in Node.js.
Example
Browser Support
The following information will show you the current browser support for the globalThis property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





