Lesson 14 of 20
Promises
Represent work that finishes later.
Introduction
A Promise is pending, fulfilled or rejected. then handles success and catch handles failure.
Promises prevent deeply nested callbacks when several asynchronous operations are connected.
Key insight
Represent work that finishes later.
Example
const wait = new Promise((resolve) => {
setTimeout(() => resolve("Ready"), 300);
});
wait.then(console.log);This example shows the core promises idea in a small, runnable program.
Real-world example
Database queries, timers and network requests commonly return promises.
Test yourself
2-question check
1
What is the main idea in Promises?
2
Where can promises 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
Create a promise that resolves with a greeting.