JavaScript Interview Prep: Microtasks vs Macrotasks

🚀 DAY 40 – JavaScript Interview Prep Asynchronous JavaScript ⭐ --- Microtasks vs Macrotasks 👨💻 Interviewer may ask: 👉 What is the difference between Microtasks and Macrotasks in JavaScript? ✅ Simple Explanation JavaScript handles async operations using the Event Loop, which decides when and in what order tasks are executed. 🔹 Microtasks (Higher Priority) : Executed right after the current call stack Always run before Macrotasks Examples: Promise.then / catch / finally queueMicrotask() MutationObserver 🔹 Macrotasks (Lower Priority) Executed after all Microtasks are completed Examples: setTimeout setInterval DOM events 🧠 One-Line Version (Quick Round) : In JavaScript, asynchronous operations are handled by the Event Loop. After the call stack is empty, the Event Loop first executes all Microtasks, and only then picks the next Macrotask. 💡 That’s why Promise.then() runs before setTimeout() #AsynchronousJavaScript #JavaScript #InterviewPrep #EventLoop #Microtasks #Macrotasks #FrontendInterview #ReactJS

  • graphical user interface

To view or add a comment, sign in

Explore content categories