Javascript Promise

Posted By :Himanshu Khurana |30th September 2019

Committed to handle asynchronous operations in JavaScript. When it comes to multiple asynchronous operations, they are easy to manage, in which callbacks can create callback helles that cause unmanageable code.


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.


Local JavaScript promises not to disclose the state of the future. Instead, he is expected to treat the promise as a black box. Only the person responsible for creating a commitment can understand the status of the promise or the rights to resolve or reject.


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.



About Author

Himanshu Khurana

Himanshu is an experienced Frontend developer with experience and capabilities to build compelling UI's for Web and Mobile Applications. Himanshu likes playing cricket and listening music.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us