It depends on if you want a value to be passed to the next promise in the chain. It is normally a good practice to return a value to the promise unless it is the last function in the chain, or there isn't information to pass on (for some reason).
If the only reason bar()
is being called is because it causes some side-effect outside the function (changes a global var, updates a DB, etc) I suppose you could not return. But even then I still would return some value for success, especially if bar()
performed I/O.
function bar(){
return 'hello world';
}
async function foo1() {
bar(); // Returns a promise with an empty value
}
async function foo2() {
return bar(); // returns a promise with the _value_ returned from bar()
}
foo1().then(console.log); // undefined
foo2().then(console.log); // 'Hello World'