Skip to main content

Command Palette

Search for a command to run...

Difference Between global and

Updated
2 min read
D

I have joined and started learning Software development with ChaiCode Web dev Cohort 2026 and very excited😊

Lets differentiate and understand about global and globalThis used in nodejs or any JS ecosystem like whether it will be in browser , nodejs, deno, web workers etc.

What is global ?

global means global object . when we console global in any environment of javascript like in browser, nodejs, deno . It prints out the object which is global in that environment .

like in browser we all know it is window object . which provides many methods , properties which we can use in our code without any install and import .

some examples like

  • console

  • setTimeout

  • setInterval

  • clearinterval

  • document

  • in nodejs (process is globa;)

What is globalThis ?

globalThis is standard javascript way to access global object .

both global and lobalThis is refers / reference to global object

so why globalThis because in many environment like in browser it called window, in nodejs it is called global so we have to remember the name to point or get info about global object so Javascript provide globalThis which works everywhere

like in

It works in:

  • Node.js

  • Browser

  • Web Workers

  • Deno

  • Everywhere

just write console.log(globalThis) to get global object.

Why was globalThis introduced?

Before globalThis, different environments used different names:

Environment Global Object
Browser window
Node.js global
Web Worker self

This made cross-platform JavaScript annoying.

So JavaScript introduced globalThis

Now one standard works everywhere.

Conclusion

to get info or point to global object globalThis is introduced so we can used it everywhere just by using globalThis keyword

B