Discovering globalThis: A Universal Global Object

💻 Learning Backend & Discovered globalThis Keyword 🚀 While understanding Node.js, I noticed something interesting — 👉 In Browser — global object is window 👉 In Node.js — global object is global 👉 In Web Workers — global object is self 👉 In Frames — frames is actually a property of window, used to access subframes, but it still points to the same global scope. 💡 In the Browser: this === window === self === frames But in Node’s global scope: this === {} (just an empty object 😅) That’s where globalThis comes in — ✨ one global object that works everywhere! globalThis === window --> true in Browser globalThis === global --> true in Node.js Now we can write universal JavaScript without worrying about the environment 😄 Big thanks to Akshay Saini 🚀 for explaining it so clearly in #NamasteNodeJS 🙌 #JavaScript #NodeJS #NamasteNodeJS #AkshaySaini #LearningBackend #WebDevelopment #CodingJourney #BackendDevelopment #Developers

  • diagram

To view or add a comment, sign in

Explore content categories