We all know that in a browser, the global object is
window. In Node.js context, the global object is
global. In a web worker, the global object is called
globalThis is trying to solve this different naming convention problem across different run time environments.
We are going to execute below code in a browser and Node.js environment.
Here is the output in browser.
Here is the browser in Nodejs.
So this addition is a one keyword solution to access global environment in any context.