Michael Landis
1 min readNov 29, 2023

--

It seems to me like the only difference is who is waiting on the main Promise, which I'm not sure actually matters.

Async functions always return Promises. If the value they're asked to return isn't already a Promise, it'll be wrapped in one.

So if you have a json() call from a fetched resource, for example, calling "return res.json()" hands the resulting promise to the calling function, who resolves it there. Calling "return await res.json()" resolves the JSON, but then wraps it in a Promise, and the calling function still resolves a Promise to get the data out.

It seems to me like, while there is a difference in where the time is spent resolving stuff, this doesn't make a material difference to the application. Adding the await after the return, however, is going to add a layer of complexity and confusion that isn't necessary.

"Hmmm, this await must be doing something important, but I can't figure out what."

--

--

Michael Landis
Michael Landis

Written by Michael Landis

Front-end web developer, React enthusiast, vagabond.

Responses (2)