Module 7 · Lesson 2 of 426/32 in the course~18 min
Module lessons (2/4)
async / await
Lesson preview5 hands-on exercises readyJavaScript Course · Module 7 — Asynchronous
Write asynchronous code that reads like synchronous code.
What you'll learn in this lesson
- Write
asyncfunctions knowing that they always return a Promise (even returning a number or string). - Suspend local execution with
awaitwaiting for a Promise to resolve without blocking the main thread's Event Loop. - Avoid unintended sequentiality by using
Promise.allwhenawaitoperations are independent of each other. - Handle
awaitPromise errors via normaltry / catchblocks.
Overview
async and await do not replace Promises: they are a more expressive syntax. Whenever you encounter await promise, only the current async function pauses, freeing the Call Stack — and everything after that await gets queued into the Microtask Queue as soon as the Promise resolves.
Sections covered in this lesson
- 1Mental model: local pause without thread blocking
- 2Progressive examples
- 3Guided laboratory
- 4Check for understanding
Pro Lesson · Module 7 — Asynchronous
Unlock "async / await" and the full JavaScript Course curriculum
Write asynchronous code that reads like synchronous code.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in JavaScript Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.