If Javascript is single-threaded, how can ‘await’ wait ?
How await works under the hood and why Javascript isn’t actually waiting
JavaScript Internals
If Javascript is single-threaded, how can ‘await’ wait ?
How await works under the hood and why Javascript isn’t actually waiting
What We’ll Explore
∘ The Illusion of Waiting ∘ The Reality: JavaScript Is Not Waiting ∘ Mental Model: Bookmarking a Chapter ∘ References ∘ Author’s Notes

The Illusion of Waiting
When developers first see await, it feels like Javascript is waiting for a result.
BUT IS IT ?
Lets look at following code :
function fetchData(){
return new Promise.resolve('some data')
}
async function doo(){
const data = await fetchData();
console.log(data);
//rest of code
}
console.log('before doo() call')
doo()
console.log('after doo() return')
Lets focus inside doo() function
...
async function doo(){
const data = await fetchData();
console.log(data);
//rest of code
}
...
- code looks synchronous, it appears as if the program pauses at
awaituntil the data arrives - But Javascript is single threaded, and if it truly waited, the entire application would freeze, the UI would stop responding.
Confusing right ? Does Javascript waits or not ?
The Reality: JavaScript Is Not Waiting
‘await’ pauses the function, not the thread.
- The code after
awaitbecomes amicrotask,- that runs whenever the
Promiseis resolved.
Lets run the above code line by line:
- Synchronous code starts :
console.log('before doo() call')Prints :before doo() call - Calls doo() :
Thread is still executing synchronously,
It hits
await fetchData();The remaining code afterawaitis scheduled as amicrotask. As a result the function pauses, it syncronously returns to the caller. - Continue after the call
console.log('after doo() return') Prints :after doo() return` - Call stack empties, microtasks run :
Call stack becomes empty.
The Event Loop processes the microtask queue where remaining portion of
doo()is ready to be executed.console.log(data);Prints :some data
Output:

Think of it like this : await transforms the function into:
function doo(){
fetchData().then((data) => {
console.log(data)
// rest of code
})
}
Of course, this transformation is only a mental model, not the exact implementation. But it explains the core idea clearly.
awaitbasically, "splits the function into two parts" Beforeawait→ run now Afterawait→ run later (microtask)
Mental Model: Bookmarking a Chapter
Think of a function as a chapter in a book.
When JavaScript reaches await in a chapter
- it places a bookmark in the chapter
- leaves the chapter for now
- continues reading other chapters (running other code)
- comes back to the bookmarked page when the Promise resolves
`'await’` doesn't stop the reader (the JavaScript thread). It just bookmarks the chapter and resumes it later.**
References
- https://33jsconcepts.com/concepts/async-await#async-await
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
Author’s Notes
I enjoy breaking down complex Javascript and algorithms into simple mental models.
If you found this useful, feel free to connect or share your thoughts by connecting with me on **linkedin**
메타데이터
- post_id
- 94a81117fa1d
- slug
- if-javascript-is-single-threaded-how-can-await-wait-94a81117fa1d
- url
- https://medium.com/@vaibhavjain301999/if-javascript-is-single-threaded-how-can-await-wait-94a81117fa1d
- canonical_url
- https://medium.com/@vaibhavjain301999/if-javascript-is-single-threaded-how-can-await-wait-94a81117fa1d
- author_url
- https://medium.com/@vaibhavjain301999
- status
- ok
- fetched_at
- 2026-07-29 13:52:11