Middle+
What are the statuses of promises?
sobes.tech AI
Answer from AI
JavaScript promises have three main states:
- Pending — the initial state, the promise is not yet settled.
- Fulfilled — the operation completed successfully, and the promise returns a result.
- 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));