Promises — States, Chaining, Error Handling
Create and use Promises: states (pending/fulfilled/rejected), chaining with then, and handling errors with catch/finally.
Intro to Promises
Goal: Learn tiny Promise patterns.
- States: pending → fulfilled/rejected
- then chaining
- catch errors
- finally cleanup

Resolve a Promise
A Promise starts pending and becomes fulfilled when you call resolve.
// Create a Promise and resolve it
function waitMs(ms) {
return new Promise(function (resolve) {
setTimeout(function () {
resolve("done");
}, ms);
});
}
console.log("Start");
waitMs(10).then(function (msg) {
console.log("Resolved:", msg);
});

All lessons in this course
- Event Loop & Task vs Microtask Basics
- Promises — States, Chaining, Error Handling
- Promise.all / any / race / allSettled — choose the right tool