const anotherPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('this is the eventual value the promise will return');
}, 300);
});
// CONTINUATION
anotherPromise
.then(value => { console.log(value) })
getSomethingWithPromise()
.then(data => {/* do something with data */})
.catch(err => {/* handle the error */})
let hw = await new Promise((resolve)=>{
resolve(“HELLO WORLD”);
})
console.log(hw);
/*basically in resolve(whatever') the whatever is returned*/
/*hw will console.log out "HELLO WORLD" */
// jeffBuysCake is a promise
const promise = jeffBuysCake('black forest')
function examplePromise(){
let promiseToReturn = new Promise(function (resolve, reject) {
let sum;
setTimeout(function(){
sum = 5 + 6;
if(sum > 10) {
resolve(sum);
}else{
reject('The promise has been rejected');
}
}, 2000);
});
return promiseToReturn;
}
console.log('some piece of code');
examplePromise().then(function(result){
console.log(result);
}).catch(function(error){
console.log(error);
});
console.log('another piece of code');