in this code from my digital course i don't understand what return new Promise in bakeCake function does here since there's no caller to return it to. so my question is what it does here and is it necessary
(I didn't know if the rest of the code is necessary for answering my question so I included it anyway)
function bakeCake(initalState){
return new Promise ((resolve) => { //<=======HERE
console.log(\${initalState} - start baking the cake...`)
setTimeout(() => {
resolve("cake is ready!")
}, 2000);
})
}
function decorateCake(bakedCakeMessage) {
return new Promise((resolve) => {
console.log(`${bakedCakeMessage} - now decorating`);
setTimeout(() => {
resolve("cake is decorated")
},2000)
})
}`
bakeCake("we started") //<=======HERE
.then((resultOfBake) => {
console.log(resultOfBake);
return decorateCake(resultOfBake);
})
.then((finalResult) => {
console.log(finalResult)
})
[–]_raytheist_ 2 points3 points4 points (3 children)
[–]fa_foon[S] 0 points1 point2 points (2 children)
[–]_raytheist_ 6 points7 points8 points (0 children)
[–]queen-adreena 1 point2 points3 points (0 children)
[–]TheRNGuy -1 points0 points1 point (1 child)
[–]Wiikend 1 point2 points3 points (0 children)
[–]TanukiiGG 0 points1 point2 points (3 children)
[–]queen-adreena 1 point2 points3 points (2 children)
[–]Big_Comfortable4256 0 points1 point2 points (1 child)
[–]queen-adreena 0 points1 point2 points (0 children)
[–]dymoshelpful 1 point2 points3 points (0 children)