examerioLogin
← Fullstack with Vue.jsQuestion 28 of 62

Why doesn't await work inside forEach()?

📘 Explanation

forEach() doesn't know about promises, so it just fires off all the callbacks without waiting for each await to finish, which is why a plain for...of loop with await is the fix. The other explanations are incorrect because forEach() doesn't convert async functions to sync, doesn't use separate threads, and await can be used inside any async function, including callbacks, not just at the top level.

Related questions

← PreviousNo login needed