BeginnerCoder

Lesson 4 — Async & promises

Results that arrive later

Reading a file or calling another server takes time. Node does not stop and wait; it carries on and gets the result later. A Promise is an object that stands for "a value that will arrive later". Inside an async function, await pauses until the promise is ready.

const msg = await wait("hello");   // msg is "hello" after the delay

Why it matters: non-blocking code is why one Node server can serve thousands of users at once.

Want it another way?
Task

Inside main(), await wait("done") and log it, so "start" prints first and "done" after the delay.

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.