Janani Umapathy’s Post

Being strong in JavaScript and TypeScript is the gateway to crack interviews. Not just surface level. Get into depth. Look into how it actually works. Trust me, it gets interesting day by day. One such concept which I loved and still love to explain and solve: Event Loop Most developers know the definition. Few actually feel how it works. Let me break it down: JavaScript is single-threaded. One call stack. One thing at a time. So how does it handle setTimeout, API calls, and UI updates — all without freezing? That's where the Event Loop steps in. Here's what's actually happening under the hood: 🔹 Call Stack — Where your code executes. Functions get pushed in, popped out. 🔹 Web APIs — setTimeout, fetch, DOM events? These are handed off to the browser. JS doesn't wait. 🔹 Callback Queue (Macrotask Queue) — Once a Web API finishes, its callback waits here. 🔹 Microtask Queue — Promises land here. Higher priority than the callback queue. 🔹 Event Loop — Constantly watching. The moment the call stack is empty, it picks from the microtask queue first, then the callback queue. A classic interview question that trips people up: console.log("1"); setTimeout(() => console.log("2"), 0); Promise.resolve().then(() => console.log("3")); console.log("4"); The Output: 1 → 4 → 3 → 2 Why? Because setTimeout goes to the callback queue, but the Promise microtask jumps ahead in priority — even with a 0ms delay. This is the kind of depth that separates a developer who uses JavaScript from one who understands it. What's your favorite JS concept that changed how you think about code? Drop it in the comments! #JavaScript #TypeScript #EventLoop #WebDevelopment #InterviewPrep #FrontendDevelopment #JSDeepDive #LearningEveryDay

closure, after realizing how it works, we can see in many places it's already there,

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories