Favorites

JavaScript globalThis Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
globalThis
JavaScript Global propertyThis property is supported by all modern browsers.
Updated 28th November 2026

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

globalThis

Value

The global object: window in browsers, self in workers and global in Node.js.

Example

console.log(globalThis === window);
var oldStyle = 1;
let newStyle = 2;
console.log('oldStyle' in globalThis, 'newStyle' in globalThis);

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.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee