0% found this document useful (0 votes)
8 views4 pages

Promise and Map Method

Uploaded by

gagangk8822
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Promise and Map Method

Uploaded by

gagangk8822
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

JavaScript Concept

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

let pobj = new Promise( )

2) Whenever we create a promise using new keyword we need to


execute a function
let pobj = new Promise( ( ) =>{
})
3) In this execute function we have to pass 2 arguments as function.
let pobj = new Promise( ( resolve, reject) =>{

})

Final syntax:
let pobj = new Promise( ( resolve, reject) =>{

})

Ex 1: resolving using then and catch


Ex 2: resolving using async and await

Map method

You might also like