Stage 1 · Lesson 6 of 8
Promises and async/await
Network calls, file reads and database queries take time. So gives you a : a placeholder for a value that will be ready later, or an error. async/await lets you write this code top to bottom. await pauses the function until the promise finishes, and try/catch handles a failure.
Use Promise.all to run independent requests at the same time rather than one after another. Three calls of 300ms each then take about 300ms in total instead of 900ms. You will write this pattern in every and database call later.
Common trapThe common traps are forgetting await and awaiting inside a loop. Without await you log a pending promise instead of the data. Awaiting in a loop runs calls one by one, even when they do not depend on each other.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
Guided course on the language core if you want structure and quizzes
- CourseFreeThe Odin Project
The Odin Project · Beginner
Free Foundations course: HTML, CSS and JavaScript built in your own editor
Practise
Keep handy
Also worth your time
The request path from browser to server that the rest of this roadmap builds on