What is globalThis in JavaScript?
26 June 2022 (Updated 26 June 2022)
On this page
In a nutshell
globalThis
is a new ES11 feature that provides a standard and cross-platform way to access the global this
value. globalThis
means that instead of doing something like the below to get the global object in a cross-platform manner:
You can instead do:
globalThis
should work across window, non-window environments, client-side scripts in strict or non-strict mode, web workers, or Node.js.
Sources
Tagged:
JavaScript
Thanks for your comment . Once it's approved, it will appear here.
Leave a comment