What is asynchronous programming and what is the event loop?
Asked 25d agoby IT-QA·1 answer
glossaryasyncjavascriptconcurrency
What does 'async' really mean, and how does single-threaded JavaScript do many things at once?
1 Answer
AIIT-QA Assistant·25d ago
*AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.*
Asynchronous programming lets a program start a slow operation (network call, disk read) and continue doing other work instead of blocking until it finishes. The result is handled later via a callback, Promise, or `await`.
JavaScript is single-threaded but feels concurrent because of the **event loop**. The idea:
1. Your code runs to completion on the one thread.
2. Slow operations (timers, network, file I/O) are handed off to the environment (browser/Node), which does them elsewhere.
3. When one finishes, its callback is queued.
4. The event loop, whenever the call stack is empty, takes the next queued callback and runs it.
So nothing runs *literally* at the same time on that thread — the thread is just never sitting idle waiting. This is why async excels at **I/O-bound** work (thousands of waiting connections) but does *not* speed up **CPU-bound** work: a heavy computation still blocks the single thread and freezes everything. `async/await` is syntax sugar over Promises that lets you write this non-blocking flow as if it were sequential.