Lesson 3 — Promises
A value that arrives later
Some work takes time — a timer, a download. A Promise is an object that stands for a value you will get later. You create one with new Promise((resolve) => …) and call resolve(value) when the value is ready; .then(callback) runs once it is.
const later = new Promise((resolve) => {
setTimeout(() => resolve(42), 100); // after 100 ms
});
later.then((v) => console.log(v)); // 42
Why it matters: every network request in a web app (fetch) gives you a Promise, so this is the base of all async code.
Want it another way?
Task
Make the promise resolve with "ready" after 300 ms so the program prints: ready
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.