globalThis
The globalThis property accesses the global this value (and hence the global object itself) across environments.
Overview
The globalThis property accesses the global this value (and hence the global object itself) across environments.
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 property accesses the global this value (and hence the global object itself) across environments.
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.
Related links
Powered by web-features