Tips For Using Async/Await in JavaScript

preview_player
Показать описание
Async/Await is a much cleaner syntax for working with promises than using .then(). Let's take a look at how to convert an asynchronous function from using .then() to using async/await and learn a few tips along the way.

00:00 - Intro
00:45 - Fetch Example with .then
01:30 - Convert Promises to Async/Await
04:40 - Use Try/Catch for Errors
06:30 - Async Functions Return a Promise
07:40 - Use IIfe for Top-Level Await

_____________________________________________

Newsletter 🗞
Interested in exclusive content and discounts? 🤯 Sign up for the newsletter!
_____________________________________________

Connect with me 😀
_____________________________________________

COURSES 💻
Рекомендации по теме
Комментарии
Автор

You just don't give a basic example of the usage of asyc/await, you give how to use them in multiple calls scenarios. Great work!!! And thank you for sharing!

TheNelsonc
Автор

I finally got the idea of async in JS, up to this moment I struggled with understanding sequences of actions when running async code. Now I understand it completely, thanks James!

QmFhbFpldnV
Автор

This has been a big help James, thanks so much! I have been struggling trying to convert promises to async/await functions and seeing you walk us through it step-by-step really helped a lot!

nikkittb
Автор

Heeey! Thanks for all that async/await content on Your channel! I did get my first junior react dev job thanks to You! I used async/await and try-catch in my tech meeting interview task, and they were impressed! I'm really, really grateful for that!

danielwisniewski
Автор

I must say I still think working with Promises is a lot more clean than working with async/await. With async/await, you end up with a lot more LOC's, you still have to deal with a promise if values are returned from the async function, or you have to use top-level async/await, which is ultimately undesirable since asynchronous code can lead to frustrating long debugging when not applied correctly in respect to synchronous code.

TheDandef
Автор

Wow!! I was literally waiting for this content...very nicely explained❤️ thanks James..

varshasingh
Автор

Clearest explanation I've found for how these all relate. Thanks!

jedirvine
Автор

Great tutorial!
You have a great, even keel persona in your presentation and that works great!

I have personal OCD sort of things around try catch I am trying to overcome. You made this much more approachable :)
Love the use of the .map call to manage the results!!! Great little trick.

ChrisLove
Автор

Loved this one! Thanks for clearing it out for me. Keep it up!! 🚀🎉

ignacioanezin
Автор

The best video that explains the two different ways of calling async function! await is always much cleaner than the .then .catch.

rexxon
Автор

this is one of the most useful videos I have watched in a long time. Thanks man 👍

ricdotnet
Автор

I'm glad there a lot of people disagreeing with you. Your video is nice and well explained, but I got to say I prefer ".then" over "async/await". I simply found it way easier to understand. It's closer to how a human would think about something asynchronous. "do this and when you will have the data, then do that." when I was learning JavaScript, the async/await was bugging me and what made me understand it was the "then"

jonathanroy
Автор

Thank you for this video. Really helped me understand not only why but how to migrate from .then to await. As a bonus, you helped me solve the multiple url problem I was going to work on this weekend! Thanks again.

LogansRun
Автор

Amazing, just about a few hours I was making several sequential fetch's to an API, and now I crossed with your video, now I feel the power, and how to make then kinda asynchronous again, thanks.

rafaelcanchola
Автор

I finally learned how to use the Promise.all method in an Async/Await function. Thanks, bro for your work...

xpoox
Автор

James, you are a legend :) have seen multiple of your videos and your approach to coding is very inspiring.

sordahl
Автор

One of the clearest explanation of async/await I have ever seen. Thanks James!!

stevenng
Автор

I can finaly say I understand all this promises and async stuff. This video was perfect to wrap it all.

InsaneMetalSoldier
Автор

Congratulations
Finally. A good path to understand. Tks man.

RobertoGPuentesDiaz
Автор

Thanks for the wonderful video. All concepts cleared. I was using multiple awaits without understanding the reason behind. The promise.All solution is fantastic. Waiting for more such tutorial.

akusa