globalThis
The globalThis global property contains the global this value, which is usually akin to the global object.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 71 | 79 | 65 | 12.1 | 71 | 12.2 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
// Works in any environment
globalThis.setTimeout(() => console.log('timer'), 100);
// No need for traditional environment checks
// const global = typeof window !== 'undefined' ? window : global; Live demo
Use cases
-
Using globalThis
The globalThis global property contains the global this value, which is usually akin to the global object.
Cautions
- No specific concerns. Stable across all major browsers.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.