Ram

Lesson 16 of 20

Async/Await

Write asynchronous code in a synchronous style.

Introduction

An async function returns a promise. await pauses that function until a promise settles without blocking the browser.

Wrap await calls in try/catch when failure needs to be handled.

Key insight

Write asynchronous code in a synchronous style.

Example

async function loadMessage() {
  const message = await Promise.resolve("Loaded");
  console.log(message);
}
loadMessage();

This example shows the core async/await idea in a small, runnable program.

Real-world example

Dashboard pages await user, product and notification data before rendering.

Test yourself

2-question check

1

What is the main idea in Async/Await?

2

Where can async/await be useful?

Ready to check your understanding?

Answer every question, then submit your quiz.

Try it yourself

JavaScript compiler

Runs in your browser. Nothing is sent to a server.

Output appears here

Practice challenge

Add try/catch around an awaited request.

Previous
Next