Saturday, January 1, 2022

Promises in javascript

 Promises is an object that keeps track of some event is happened or not .

--Determines what happens after the event has happened.

Promise have different states -


Example :                                                                                                        
const ids = new Promise((resolve, reject) => {
setTimeout(() => {
                                                                                         resolve([100, 200, 300, 400, 500]);
                                         }, 1500);
                 });
//Consuming promises
                                    ids.then(ids=>{//ids will store all the result
   console.log(ids); 
})

                                                 .catch(error=>{//catch is used if error has occured
   console.log(error); 
});





    





No comments:

Post a Comment

Element of a good table (Ref: Database design mere mortals by Michael J. Hernandez)

  Elements of the Ideal Table: It represents a single subject, which can be an object or event that reduces the risk of potential data integ...