globalThis
The global object, available the same way in browsers, workers and Node.js.
Available since: ES2020
Syntax
globalThisReturn value
objectThe global object: window in a browser, self in a worker, global in Node.js.
Examples
Built-in functions are properties of the global object:
console.log(globalThis.parseInt === parseInt);
console.log(typeof globalThis.setTimeout);Output:
true
functionNotes
Previously the global object had a different name in each environment and code had to adapt. Avoid creating your own globals — use modules.
See also
In the tutorial
- Scope — Where variables are visible in JavaScript — local and global variables, block scope and shadowing.