doSomething()
.then(function(result) {
return doSomethingElse(result);
})
.catch(failureCallback);
var doSome = new Promise(function(resolve, reject){
resolve('I am doing something');
});
doSome.then(function(value){
console.log(value);
});
new Promise( (res, rej) => {
setTimeout(() => res(1), 1000);
}).then( (res) => {
console.log(res); // 1
return res*2
}).then( (res) => {
console.log(res); // 2
});
promiseObject.then(onFulfilled, onRejected);
const promise2 = doSomething().then(successCallback, failureCallback);
Promise me that you’ll go to the supermarket
.then(you’ll make dinner with the ingredients you bought)
.then(i’ll do the washing up)
we can only use await keyword before a function that
returns either a promise or is itself async.
Note: we can use async function or function returning
a Promise with .then()