# Difference Between global and 

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.

![](https://cdn.hashnode.com/uploads/covers/6950c18c622afddd90b193eb/430c4742-2c1a-4f16-a7a9-edf0cb5d6d4f.png align="center")

## 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
