0Pricing
JavaScript Academy · Lesson

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
Promises — States, Chaining, Error Handling — illustration 1

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);
});
Promises — States, Chaining, Error Handling — illustration 2

All lessons in this course

  1. Event Loop & Task vs Microtask Basics
  2. Promises — States, Chaining, Error Handling
  3. Promise.all / any / race / allSettled — choose the right tool
← Back to JavaScript Academy