Manuals / JavaScript / Chapter 7
C · Async · intermediate · Week 4–5 · Chapter 7 of 14
Promises & async/await
JavaScript is single-threaded but non-blocking. Promises represent future values. async/await is syntactic sugar over Promises — readable sequential async code. Promise.all for parallel, Promise.race for first-wins. Always handle rejections.
Path progress44%
Step 1 of 5
Promise basics
new Promise((resolve, reject) => ...) wraps async work. .then handles success, .catch handles failure. A Promise is pending → fulfilled or rejected once.
Example
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
delay(1000).then(() => console.log("done"))Do this now
Wrap setTimeout in a delay(ms) function returning a Promise. Chain .then to print "done" after 1 second.
Was this step clear?
Chapter learning outcomes
- Callback → Promise mental model
- then/catch/finally
- async/await
- Promise.all / Promise.allSettled
- Error propagation
Chapter videos
Clear these before you leave
Side quest
Async pipeline
Load user IDs from a JSON file, fetch each user from JSONPlaceholder in parallel (max 3 concurrent), aggregate results.