What is globalThis in Javscript?
globalThis Is a way to access the global object without worrying much about javascript environment. Whether you are working in browser, nodejs or any javascript runtime environment, globalThis will make sure to provide access to the global object.
Before globalThis, if you want to access global object you have to write environment specific code to access the global object, like this
In Browser - The global object can be accessible using window.
In Nodejs - The global object can be accessible using global.
See, how you can access global object using same globalThis keyword without checking or worrying about specific environment.
Subscribe to my newsletter
Read articles from Parveen Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Parveen Kumar
Parveen Kumar
I am a Full-stack MERN engineer with a product centric approach, specializing in the design and development of scalable, reliable, production ready web application, I bring expertise in JavaScript, React, and Node Js. Get in touch! paulparveen01@gmail.com