Stage 2 · Lesson 7 of 10
Promises and async/await
Anything that takes time in the browser, such as a network request or a timer, is . Your code starts it and carries on, and the result arrives later. stand for that future result.
Each one starts pending, then is either fulfilled with a value or rejected with an error. and await let you write this as straight line code: const res = await fetch(url) pauses that one function, not the whole page. Handle failure with try and catch.
Run independent requests together with Promise.all, instead of awaiting them one after another. The two classic traps are forgetting await, so you get a promise instead of data, and having no catch, so failures vanish silently.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
Guided beginner course on the language core, with quizzes after every chapter
- GuideFreeJavaScript.info
Ilya Kantor
Free and thorough: Part 1 for the language, Part 2 for the DOM and events, Part 3 for fetch
Practise
Keep handy
Also worth your time
- You Don't Know JS YetGo deeper
For when scope, this, coercion or async behaviour still feel like magic