flâneur — a map of the web's best reading

'return await promise' vs 'return promise' in JavaScript

dmitripavlutin.com · 737 words · saved by 1 readers

Is there any difference between using 'return await promise' and 'return promise' in asynchronous JavaScript functions?

'return await promise' vs 'return promise' in JavaScript Posted August 10, 2021 javascript promise async -- Comments When returning from a promise from an asynchronous function, you can wait for that promise to resolve return await promise , or you can return it directly return promise : async function func1() { const promise = asyncOperation(); return await promise; } // vs async function func2() { const promise = asyncOperation(); return promise; } You'll see shortly that both expressions do work. However, are there cases when these expressions behave differently? Let's find out! 1. Same beh

Explore this link on the map →

related reading