Widely availableSupported across all major browsers. Safe to use in production.

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

globalThis Basics

gro-balobject readstandardAPI.

PreviewFullscreen

Property. Add

GlobalThis to property add and all from aksespossible to.

PreviewFullscreen

Usage and Key Considerations

rairari or porifuilemit in usage.gro-bal to is note.

PreviewFullscreen

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.

Powered by web-features