{
  "id": 10667052,
  "title": "I Used JavaScript Promises Every Day. Then I Asked: How Does JavaScript Actually Handle Them?",
  "url": "https://urgent.news/2026/09/29/i-used-javascript-promises-every-day-then-i-asked-how-does-javascript",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-29T10:24:20.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/mhasanjoy/i-used-javascript-promises-every-day-then-i-asked-how-does-javascript-actually-handle-them-3fki"
  },
  "original_language": "en",
  "account": "The author, who had been using JavaScript promises in daily programming, decided to investigate how JavaScript actually handles them. They presented a simple example function main() that logs A, then uses setTimeout to log B after a delay, creates a new Promise that logs C, then uses the .then() method to log D, and finally logs E. Despite JavaScript's single-threaded nature, with the main thread responsible for executing JavaScript code, the output was ACEDB.\n\nThe key to understanding this lies in how JavaScript processes asynchronous operations. When the program invokes main(), it is added to the call stack and begins executing synchronously. The first console.log( A ) runs, then setTimeout() is called, with its timer handled by the JavaScript environment rather than the call stack. After that, the Promise is created, and its executor function runs synchronously, printing C and resolving the Promise by calling resolve(D). However, the callback function for .then() does not execute immediately. Instead, it is added to the microtask queue, which is processed after the current synchronous code has finished running.\n\nAfter printing E, the main() function completes, and the call stack becomes empty. At this point, the event loop can proceed to process queued asynchronous work. Since microtasks have priority over tasks, the Promise's .then() callback runs first, printing D. Finally, once the microtask queue is processed, the timer callback for setTimeout() can execute, printing B. Thus, the final output is ACEDB.\n\nThis JavaScript asynchronous workflow reveals that the Promise executor itself is synchronous, printing C synchronously, but the execution of the .then() callback is asynchronous, occurring after the Promise has been resolved. The simplified flow of asynchronous operations in JavaScript can be described as: Call Stack → Execute synchronous JavaScript → Call stack becomes empty → Process Microtasks → Process next Task. Understanding this behind-the-scenes behavior of JavaScript promises can greatly simplify reasoning about asynchronous code.",
  "summary": "I've used promises for everyday programming. I knew how to use promises, but I never questioned how JavaScript actually handles promises and asynchronous programming. Take this one for example: function main () { console . log ( \" A \" ); setTimeout (() => { console . log ( \" B \" ); }, 0 ); new Promise ( resolve => { console . log ( \" C \" ); resolve ( \" D \" ); }). then ( value => { console . log (…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}