Promise and Map Method
Promise and Map Method
Promises:
It is an object.
It will always see the event you are performing whether it is completed or
not.
It will keep track on what we are doing
3 Stages:
1) Pending state :
This is the initial state, neither fulfilled nor rejected. This means that the
asynchronous operation hasn't completed yet.
2) Resolved state :
This means that the operation completed successfully and the Promise
now has a value. This value is often referred to as the fulfillment value.
3) Rejected state:
This means that an error occurred during the operation, and the Promise
is rejected with a reason (usually an Error object) explaining what went
wrong.
Note :
Whenever we have promise we need to resolve it.
We can resolve it by either using async and await or then and catch
How to create a promise ?
1) Create a Promise constructor
})
Final syntax:
let pobj = new Promise( ( resolve, reject) =>{
})
Map method