Course contentsShow
← JavaScript
Lesson 1267 of 2,72329. PromisesFree lesson

Resolving a Promise

Call resolve(value) inside the executor to transition the promise from pending to fulfilled with a value.

Resolving a Promise

You'll learn how to transition a promise from pending to fulfilled by calling resolve with a value.

What Does Resolving Mean?

When you create a Promise, it starts in a pending state — waiting for something to complete. To signal success, you call the resolve function that's provided as the first parameter to your executor function. This transitions the promise from pending to fulfilled and stores the value you pass to resolve.

Think of it like completing a food order: when you create a Promise (place an order), it's pending. When the chef finishes cooking and hands you the meal, that's like calling resolve(meal) — the promise is fulfilled with the meal as its value.

How It Works

Inside your executor function, you control when to call resolve:

const myPromise = new Promise((resolve, reject) => {
  // Do some work...
  const result = 42;
  
  // Signal success by calling resolve
  resolve(result);
});

// The promise is now fulfilled with the value 42

You typically call resolve after an asynchronous operation completes successfully:

const delayedValue = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve("Done!");
  }, 1000);
});

// After 1 second, this promise becomes fulfilled with "Done!"

You can resolve with any value: strings, numbers, objects, arrays, or even other promises. Once a promise is resolved, it stays resolved — calling resolve again does nothing.

Key Takeaway: Calling resolve(value) inside the executor function fulfills your promise with that value, signaling successful completion and making that value available to consumers of the promise.