Web Dev Roadmap for Beginners (Free!): https://bit.ly/DaveGrayWebDevRoadmap
Attempting to use Async / Await with forEach is a bad idea. In this advance async/await Javascript tutorial, I'll show you why. You will learn how for, for...of, Promise.all(), and reduce all provide alternative solutions that are better than forEach.
Subscribe https://bit.ly/3nGHmNn
This tutorial is part of an Advanced Javascript Concepts tutorial series playlist:
https://www.youtube.com/playlist?list=PL0Zuz27SZ-6N3bG4YZhkrCL3ZmDcLTuGd
Async Await with forEach is BAD! | Advanced Async/Await Javascript Tutorial
(00:00) Intro
(00:05) Welcome and Intro
(00:22) forEach - What's it good for?
(02:34) Async fetch request example
(03:51) forEach with Async Await is BAD
(07:33) Alternative #1: traditional for loop
(09:39) Alternative #2: for...of loop
(10:39) Alternative #3: Promise.all with map
(14:01) Alternative #4: A different reduce
References:
MDN forEach:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
MDN for...of:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
MDN PromiseAll:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
MDN reduce:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
Follow Me:
Twitter: https://twitter.com/yesdavidgray
LinkedIn: https://www.linkedin.com/in/davidagray/
Blog: https://yesdavidgray.com
Reddit: https://www.reddit.com/user/DaveOnEleven
Was this tutorial about why forEach is not for use with Async/Await in Javascript helpful? If so, please share. Let me know your thoughts in the comments.
#foreach #async #await