I was of the understanding that the then()
promise method always itself returns a promise. Promises are something I'm still getting used to being a bit of a newb, so I've just been going over some examples and tinkering. The following example shows that the return value of the then
method is an object.
const foo = true;
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
if (foo) {
resolve('Do this');
} else {
reject(Error("Do that"));
}
}, 1500)
})
const bar = myPromise.then(value => value);
console.log(typeof bar); // object
Is this the same as returning a promise? Or do I need to explicitly tell then
to return a promise like so (pseudocode, I know not correct) :
.then(value => {
// do something
return new Promise;
})
I want to make sure I've got this. Really appreciate the help.