Skip to main content
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 async functions knowing that they always return a Promise (even returning a number or string).
  • Suspend local execution with await waiting for a Promise to resolve without blocking the main thread's Event Loop.
  • Avoid unintended sequentiality by using Promise.all when await operations are independent of each other.
  • Handle await Promise errors via normal try / catch blocks.

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

  1. 1Mental model: local pause without thread blocking
  2. 2Progressive examples
  3. 3Guided laboratory
  4. 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.