JS Macro vs Micro tasks: A debugging nightmare

👀 JS Macro vs Micro tasks: A very important concept of JS, often ignored, but can put you in hours long debugging sessions 😂 🧩 Basically, JS doesn’t just have one queue — it has two (if categorized majorly on priority basis): Macrotasks: timers, I/O, setTimeout, etc. Microtasks: promises, queueMicrotask, process.nextTick etc. Microtasks run right after the current stack — before the next macrotask. So even a setTimeout(..., 0) gets delayed behind promises. That’s why code like attached image prints in this order: ``` promise timeout ``` You can read more about this in the article below: https://lnkd.in/gEjWn3_S #JavaScript #NodeJS #EventLoop #AsyncProgramming #WebDevelopment #SoftwareEngineering #LearnInPublic

  • graphical user interface, text, application

Anyone out there who had this kinda unlucky time? 🥴

Like
Reply

To view or add a comment, sign in

Explore content categories