Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

globalThis

The global object, available the same way in browsers, workers and Node.js.

Available since: ES2020

Syntax

globalThis

Return 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
function

Notes

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

  • var — The legacy way to declare a variable.
  • let — Declares a variable whose value can change.

In the tutorial

  • Scope — Where variables are visible in JavaScript — local and global variables, block scope and shadowing.

Thanks for reading!

Donate to the site — we work hard for you.