Promise vs setTimeout - Which Runs First? Event Loop Mechanics

Опубликовано: 16 Июнь 2026
на канале: Hareesh Rajendran
14,515
421

Javascript Event Loop and Queues - Vanakkam Javascript - JS Tutorial | Tamil | 2025 | Part 3

This video is made in collaboration with JS Lovers Community.

Everything covered in this video is explained in detail in the following link : https://dev.to/jslovers/mastering-asy...

Chapters:
00:00 Intro
00:50 Single-Threaded Language
01:20 Call Stack
02:28 Web APIs
07:23 JS execution Flow
07:55 Example 1 (Basic)
11:50 Example 2
19:12 Example 3 (Advanced)
27:09 Task Starvation
28:38 Key Takeaways
29:50 Conclusion

Learn how the browser event loop, task queue, microtask queue, and Web APIs work together to enable non-blocking, asynchronous JavaScript.

JavaScript is a synchronous, single-threaded language, but async operations like setTimeout, fetch, and event listeners rely on the event loop, microtasks, and macrotasks for execution.

🔹 Key Concepts:
✅ JavaScript executes synchronous code first.
✅ Asynchronous tasks use Web APIs and the event loop.
✅ Microtasks (Promises, MutationObserver) execute before Macrotasks (setTimeout, event listeners).
✅ Fetch responses (microtasks) execute before setTimeout callbacks (macrotasks).
✅ Task starvation can occur if microtasks keep running without allowing macrotasks.

By mastering these, you can write efficient & bug-free async JavaScript! 🚀

Whatsapp Channel: https://whatsapp.com/channel/0029VaYI...
Join Membership:    / @hareeshrajendran  

📢📢📢📢 Social Media Links 📢📢📢📢

Mentorship 1:1 : https://www.meetmymentor.me/hareesh_r...
Buy me a coffee ☕️ : https://www.buymeacoffee.com/hareeshr...
LinkedIn:   / hareesh-r  
Instagram:   / hareesh_._r  
Facebook:   / hareeshprogrammer  
Twitter:   / hareesh_dev  
GitHub: https://github.com/hareesh-r

Curious to know more about me?: https://hareesh.web.app🚀

Your support means the world to me! 🙌 Let's build an awesome community together. 🌍✨