Promises
Promises
@webbysaif
Settled - This state represents that the promise has been either
rejected or fulfilled.
Saif Mujawar
@webbysaif
new Promise()
resolve() reject()
Go to next action Handle Error
Example of a promise:
Promises are used to handle asynchronous operations like server requests, for
ease of understanding, we are using an operation to calculate the sum of three
elements.
Saif Mujawar
@webbysaif
In the code above, we are calculating the sum of three elements, if the length of
the elements array is more than 3, a promise is rejected, or else the promise is
resolved and the sum is returned.
We can consume any promise by attaching then() and catch() methods to the
consumer.
.then() .then()
.catch()
Saif Mujawar
@webbysaif
then() method is used to access the result when the promise is fulfilled.
useful?
Saif Mujawar
@webbysaif