Sobes.tech
Middle+

What are the statuses of promises?

sobes.tech AI

Answer from AI

JavaScript promises have three main states:

  1. Pending — the initial state, the promise is not yet settled.
  2. Fulfilled — the operation completed successfully, and the promise returns a result.
  3. Rejected — the operation failed with an error, and the promise returns a reason for rejection.

Example:

const promise = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('Success'); // or reject('Error');
  }, 1000);
});

promise.then(result => console.log(result))
       .catch(error => console.error(error));
What are the statuses of promises? — Frontend - sobes.tech