Promise
var myPromise = new Promise(function(resolve, reject){
var itemRequested = 10;
if(itemRequested === 10 ){
resolve("Happy to offer you 100 Rs.");
}
if(itemRequested === 'star'){
reject("It's false hope");
}
});
myPromise.then(function(res){
console.log(res)
}, function(res){
console.log(res)
})Promise Chaining
catch
Promise.all
Promise.all demo
If any promise is rejected the catch fires for the first rejection:
Promise.all demo
Promise.race
Ex - Native xhr request
fetch api return promise
Last updated