Events and callbacks were used before the promise, but they were limited in functionality and created hard-to-manage code.
Multiple callback functions will create a callback hell, resulting in unmanageable code.
These events are not intended to handle asynchronous operations.
Promise is ideal for handling asynchronous operations in the simplest way. They can handle multiple asynchronous operations with ease and provide better error handling than callbacks and events.
Commitment is an object that can generate a single value in the future: a resolved value or unresolved cause (such as a network error). Commitment can be in one of three possible states: fulfilling, rejecting or pending. Promise users can attach a callback to handle the value of the performance or the reasons for the refusal.
How Promises Work
A promise is an object that can be returned synchronously from an async function. It will be in one of three possible states:
Completed: onFulfilled () will be called (for example, call resolve ())
Rejected: onRejected () will be called (for example, it is called reject ())
To be determined: Not yet achieved or rejected
If a commitment is not pending (has been resolved or rejected), the commitment will be resolved. Sometimes people use the same thing to solve and build meaning: there is no waiting.
Once resolved, promises can not be relocated. Calling resolve () or reject () again will not work. The immutability of established promises is an important feature.
The promise of following a specification must follow a specific set of rules:
A promise or 'ableable' is an object that provides a rule-compliant method .then ().
Unresolved pledges can be transferred to fulfillment or rejection of the state.
The promise of fulfillment or rejection has been resolved and should not be passed on to any other country.
Once committed, it must have a value (which may not be defined). This value should not change.
I hope this blog is Helpful for all.