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