Section 3 · Functions, arrays & objectsHD · Subtitles
// fetch a user, then their courses
async function loadCourses(id) {
const user = await getUser(id);
const list = await getCourses(user);
return list.filter(c => c.active);
}
0:00 / 24:05
About this lesson
Callbacks and promise chains can get messy fast. In this lesson you'll rewrite a real data-loading function with async/await, learn how errors flow through try/catch, and see when to run requests in parallel with Promise.all.
- Turn a promise chain into readable async code
- Handle network errors without crashing the app
- Speed things up by running requests in parallel
JB
Jonas Berg · 3 days ago
Why doesn't await work inside forEach?
Maya Chen Instructor
Great question! forEach ignores the promises your callback returns. Use a for…of loop, or map + Promise.all to run them in parallel.
EM
Elif Musa · 1 week ago
Is top-level await safe to use in the browser now?
Lesson complete! +50 XP