DEV Community

Discussion on: JavaScript async and await

mywebstuff_hq profile image
Mayer János

Not completely, as there is one case when it can be beneficial to use return await. Let's say you have three async functions, A,B and C, where A calls B, and B calls C.
Function B calls function C in a try-catch block. If B just returns the promise returned by function C than B puts the burden of error handling on function A as it's catch block will never be called. However if it uses return await C() and C rejects the promise, the erro will be handled by function B's catch block.
I might be making this waaay more complicated than it really is so here is Jake Archibald doing it much better than I did :)

zellwk profile image
Zell Liew 🤗 Author

Way too complicated lol. I just do this:

async function test () {
await a
await b
Return c


If C errors out, I still catch it with handleError.