globalThis
The globalThis global property refers to the global object, which holds the built-ins and global variables that every part of a program can reach. It gives browsers, Web Workers, and server runtimes one shared name for that object, which older code reached through host-specific names such as window, self, and global:
> globalThis.Math === Math
true
> globalThis === global
true
globalThis was added in ES2020. The global object it points to can’t be constructed or called. Its prototype is host-defined, and each host adds its own properties, such as setTimeout() and fetch(), next to the ECMAScript built-ins.
Key Properties
The global object holds every global the language and the host define. This table shows representative members of each kind:
| Member | Kind | Description |
|---|---|---|
globalThis.globalThis |
Value property | Refers back to the global object itself |
globalThis.undefined |
Value property | Holds the read-only undefined value |
globalThis.NaN |
Value property | Holds the read-only not-a-number value |
globalThis.Infinity |
Value property | Holds read-only positive infinity |
globalThis.parseInt() |
Function property | Exposes a global function, like isNaN() and encodeURIComponent() |
globalThis.Array |
Constructor property | Exposes a constructor, like Map, Promise, and Error |
globalThis.Math |
Namespace property | Exposes a namespace object, like JSON, Reflect, and Intl |
globalThis.setTimeout() |
Host property | Exposes a host-provided global, like console and structuredClone() |
The globalThis property itself is writable and configurable but not enumerable, so it doesn’t show up in Object.keys(globalThis).
Examples
A library that runs both in browsers and on the server can check for a browser API before touching it. Reading a missing name throws, while the in operator on globalThis returns false:
> "document" in globalThis
false
> document
Uncaught ReferenceError: document is not defined
A test setup that needs one counter shared by every module can store it on the global object. Assigning a property creates a global variable that bare names can read and update:
> globalThis.requestCount = 0;
0
> requestCount += 1;
1
> globalThis.requestCount
1
Code inside an ES module can’t rely on top-level this, because it’s undefined there. The globalThis property still reaches the global object:
module-scope.mjs
console.log(`Top-level this: ${this}`);
console.log(`Same Array: ${globalThis.Array === Array}`);
Running the module shows both values:
$ node module-scope.mjs
Top-level this: undefined
Same Array: true
Common Gotchas
Only some top-level declarations become properties of the global object. In a classic script or the REPL, var and function declarations do, while let, const, and class declarations don’t:
> var region = "eu-west";
undefined
> let stage = "beta";
undefined
> globalThis.region
'eu-west'
> globalThis.stage
undefined
Top-level declarations in an ES module stay local to that module, so none of them appear on globalThis.
In browsers, globalThis refers to a WindowProxy that wraps the current Window object, not the Window itself. Pages rarely notice the difference, but it keeps a reference to another frame’s global object valid after that frame navigates.
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 4, 2026