function foo(num) {
return new Promise((resolve) => console.log(num));
}
foo(1).then(() => {
foo(3);
});
The function foo returns an immediately resolve promise. "1" is printed, but why doesn’t the chain continue with printing "3"?
function foo(num) {
return new Promise((resolve) => console.log(num));
}
foo(1).then(() => {
foo(3);
});
The function foo returns an immediately resolve promise. "1" is printed, but why doesn’t the chain continue with printing "3"?
2
Answers
You need to
resolve
Promise
like this:@JobHunter69 The function foo indeed creates a promise but does not explicitly call resolve() to resolve the promise. Therefore, the promise returned by foo never completes or resolves.