Explain the difference between the "pending," "fulfilled," and "rejected" states of a Promise.
home / developersection / forums / explain the difference between the "pending," "fulfilled," and "rejected" states of a promise.
Explain the difference between the "pending," "fulfilled," and "rejected" states of a Promise.
Aryan Kumar
26-Sep-2023The three states of a Promise in JavaScript—pending, fulfilled, and rejected—represent different stages in the lifecycle of the asynchronous operation the Promise represents. Here's an explanation of each state:
Pending:
Fulfilled:
Rejected:
Here's a visual representation of how a Promise can transition between these states:
In summary, the pending state represents the ongoing asynchronous operation, fulfilled represents a successful completion with a result value, and rejected represents an error or failure with an associated reason. Promises provide a structured way to work with asynchronous code and handle different outcomes, making it easier to manage asynchronous flows and error handling in JavaScript.