<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-qkr1ufg7o" -->

---
title: How the JavaScript Runtime Schedules Callbacks: A Look...
description: An explanation of how JavaScript's single-threaded runtime avoids blocking on slow operations like network requests and timers, covering the call stack, Web...
canonical: https://daily.dev/posts/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-qkr1ufg7o
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How the JavaScript Runtime Schedules Callbacks: A Look at the Event Loop | daily.dev
og:description: An explanation of how JavaScript's single-threaded runtime avoids blocking on slow operations like network requests and timers, covering the call stack, Web...
og:url: https://daily.dev/posts/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-qkr1ufg7o
og:image: https://api.daily.dev/og/posts/Qkr1UfG7O.png
og:image:alt: How the JavaScript Runtime Schedules Callbacks: A Look at the Event Loop
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How the JavaScript Runtime Schedules Callbacks: A Look at the Event Loop

**[Medium](https://daily.dev/sources/medium_js)** · 8 min read · 4 upvotes · 0 comments

## Summary

An explanation of how JavaScript's single-threaded runtime avoids blocking on slow operations like network requests and timers, covering the call stack, Web APIs, and the event loop. It breaks down the difference between the macrotask queue (setTimeout, DOM events, I/O) and the microtask queue (Promises, queueMicrotask), showing why microtasks always fully drain before the next macrotask runs. A traced code example demonstrates why 'start, end, promise, timeout' is the correct output order, and why setTimeout(fn, 0) doesn't mean immediate execution. It closes by showing Node.js uses the same single-thread-plus-event-loop model via libuv, which is why it can handle many concurrent connections without blocking.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://artclick-inc.medium.com/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-14e17b9ef7c0>

## Questions this post answers

### Why does a Promise callback run before a setTimeout callback with a delay of 0?

The microtask queue, which holds Promise callbacks, is always fully drained before the event loop moves to the next macrotask, and setTimeout callbacks are macrotasks. So after the synchronous code finishes, any pending .then() callbacks execute first, then queued timeout callbacks run, even if the timeout delay was 0ms.

_Developers debugging async ordering issues can dig deeper into event loop mechanics on daily.dev._

### Does setTimeout with a delay of 0 milliseconds run the callback immediately?

No, a zero-delay setTimeout does not run next; it still gets placed in the macrotask queue and only runs once the current call stack is clear and every pending microtask (like Promise callbacks) has been handled. It effectively means 'run as soon as possible after everything already queued,' not 'run immediately.'

_Anyone tracing timing bugs in async JavaScript can compare notes on the event loop via daily.dev._

### Why can a single-threaded Node.js process handle thousands of concurrent connections?

A single Node.js process handles many concurrent connections because slow I/O operations like database calls and file reads are delegated to libuv rather than blocking the one JS thread; each request's callback is queued and run once the thread frees up, so the thread never sits idle waiting on I/O.

_Backend developers scaling Node services can explore event-loop concurrency patterns on daily.dev._

## Similar posts on daily.dev

- [Stop Calling Node.js “Single-Threaded”: A Look Under the Hood](https://daily.dev/posts/stop-calling-node-js-single-threaded-a-look-under-the-hood-ofsmhbjmm) · Medium · 6 upvotes · 0 comments
- [JavaScript Event Loop Explained: Queue Tracing and Debugging Guide](https://daily.dev/posts/javascript-event-loop-explained-queue-tracing-and-debugging-guide-sa0thbcrm) · SitePoint · 149 upvotes · 4 comments
- [JavaScript Microtasks vs Tasks: What Runs First?](https://daily.dev/posts/javascript-microtasks-vs-tasks-what-runs-first--zlnrvrlzg) · Medium · 138 upvotes · 5 comments
- [Mastering the JavaScript Event Loop](https://daily.dev/posts/mastering-the-javascript-event-loop-xrcdqa1q5) · freeCodeCamp · 26 upvotes · 0 comments
- [Rendering Is a Browser Decision, Not a JavaScript One](https://daily.dev/posts/rendering-is-a-browser-decision-not-a-javascript-one-ukimtnhiq) · Code Like A Girl · 3 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#nodejs](https://daily.dev/tags/nodejs)

[View this post on daily.dev](https://daily.dev/posts/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-qkr1ufg7o)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How the JavaScript Runtime Schedules Callbacks: A Look at the Event Loop","url":"https://daily.dev/posts/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-qkr1ufg7o","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-qkr1ufg7o"},"datePublished":"2026-08-27T11:53:11.932Z","dateModified":"2026-09-14T08:25:39.332Z","description":"An explanation of how JavaScript's single-threaded runtime avoids blocking on slow operations like network requests and timers, covering the call stack, Web...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5f2aa76021170e9bc045020530093b3d?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5f2aa76021170e9bc045020530093b3d?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-qkr1ufg7o","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,nodejs","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"How the JavaScript Runtime Schedules Callbacks: A Look at the Event Loop"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-the-javascript-runtime-schedules-callbacks-a-look-at-the-event-loop-qkr1ufg7o#faq","mainEntity":[{"@type":"Question","name":"Why does a Promise callback run before a setTimeout callback with a delay of 0?","acceptedAnswer":{"@type":"Answer","text":"The microtask queue, which holds Promise callbacks, is always fully drained before the event loop moves to the next macrotask, and setTimeout callbacks are macrotasks. So after the synchronous code finishes, any pending .then() callbacks execute first, then queued timeout callbacks run, even if the timeout delay was 0ms. Developers debugging async ordering issues can dig deeper into event loop mechanics on daily.dev."}},{"@type":"Question","name":"Does setTimeout with a delay of 0 milliseconds run the callback immediately?","acceptedAnswer":{"@type":"Answer","text":"No, a zero-delay setTimeout does not run next; it still gets placed in the macrotask queue and only runs once the current call stack is clear and every pending microtask (like Promise callbacks) has been handled. It effectively means 'run as soon as possible after everything already queued,' not 'run immediately.' Anyone tracing timing bugs in async JavaScript can compare notes on the event loop via daily.dev."}},{"@type":"Question","name":"Why can a single-threaded Node.js process handle thousands of concurrent connections?","acceptedAnswer":{"@type":"Answer","text":"A single Node.js process handles many concurrent connections because slow I/O operations like database calls and file reads are delegated to libuv rather than blocking the one JS thread; each request's callback is queued and run once the thread frees up, so the thread never sits idle waiting on I/O. Backend developers scaling Node services can explore event-loop concurrency patterns on daily.dev."}}]}
```

