Concept
A Promise stands for a value that arrives later. async functions return one, and await pauses inside them until it settles, which makes asynchronous code read top to bottom.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Promises and async/await doing its job.
async function loadUser(id: string): Promise<User> {
const response = await fetch("/api/users/" + id);
if (!response.ok) throw new Error("HTTP " + response.status);
return (await response.json()) as User;
}
loadUser("7")
.then((user) => console.log(user.name))
.catch((error) => console.error(error));Forgetting await, so a Promise<User> is used where a User was expected. Calling .name on it gives undefined, and a thrown error inside becomes an unhandled rejection instead of reaching your catch.
Your roadmap puts these before Promises and async/await, unless you already know them.
Once a session shows you understand Promises and async/await, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Promises and async/await.