BeginnerCoder

Lesson 4 — async / await

Pause a function, not the program

An async function can use await in front of a Promise: the function pauses there until the Promise is done, while the rest of the program keeps running. That is why code after the call can print first.

const wait = (ms) => new Promise((r) => setTimeout(r, ms));
async function demo() {
  await wait(100);
  console.log("second");
}
demo();
console.log("first");

Why it matters: await lets you write step-by-step code for slow work without freezing the page.

Want it another way?
Task

Add an await so "started" prints before "done".

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.