Skip to main content

How does resolve differ from reject?

Short answer

  • resolve(value) - signals that the operation completed successfully → the promise becomes fulfilled.
  • reject(reason) - signals that the operation completed with an error → the promise becomes rejected.

Both move the promise from pending → to a final (settled) state, but down different result "branches".

Example

javascript
const promise = new Promise((resolve, reject) => { const success = Math.random() > 0.5; if (success) { resolve('Everything went well'); } else { reject('An error occurred'); } }); promise .then(result => console.log('then:', result)) .catch(error => console.log('catch:', error)) .finally(() => console.log('finally'));

Possible output:

javascript
then: Everything went well finally

or

javascript
catch: An error occurred finally

How they work

MethodWhat it doesPromise stateWhat it triggers
resolve(value)Completes the promise successfully, passes the valuefulfilled.then(value => …)
reject(reason)Completes the promise with an error, passes the reasonrejected.catch(error => …)

After one of them is called:

  • the promise is "settled",
  • a further call to resolve or reject is ignored.

Example: resolve

javascript
const promise = new Promise((resolve) => { setTimeout(() => { resolve('Data received!'); }, 1000); }); promise.then(result => console.log(result));

After 1 second:

javascript
Data received!

The promise moved to the fulfilled state.

Example: reject

javascript
const promise = new Promise((resolve, reject) => { setTimeout(() => { reject('Network error'); }, 1000); }); promise.catch(error => console.error(error));

After 1 second:

javascript
Network error

The promise moved to the rejected state.

Important: the state can only change once

javascript
const promise = new Promise((resolve, reject) => { resolve('OK'); reject('Error'); // ignored }); promise.then(console.log).catch(console.error);

After the first call (resolve) the promise became fulfilled, and the second call (reject) has no effect.

Example: resolve with another promise

If you pass another Promise to resolve(), the current promise waits for it to settle.

javascript
const inner = new Promise((resolve) => setTimeout(() => resolve('Inner result'), 1000)); const outer = new Promise((resolve) => resolve(inner)); outer.then(console.log); // logs "Inner result" after 1 sec.

This is called promise unwrapping.

Handling the results

javascript
new Promise((resolve, reject) => { resolve('OK'); }).then(console.log); // OK new Promise((resolve, reject) => { reject('Error'); }).catch(console.error); // Error

Analogy

Think of a promise as a delivery:

  • resolve → the courier delivered the package (everything succeeded)
  • reject → the courier called and said: "address not found" (error)

SUMMARY

MethodStateWhat it passesHandled whereAnalogy
resolve(value)fulfilledThe successful result.then()Package delivered
reject(reason)rejectedThe error / rejection reason.catch()Courier could not deliver
After the callThe promise becomes settled and cannot be changed anymore---

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.