JavaScript Async/Await In 90 Seconds #JavaScriptJanuary

preview_player
Показать описание
Watch the entire #JavaScriptJanuary series from the beginning!

It is essential to understand how promises work before learning Async/Await since Async/Await is basically just syntactic sugar wrapped around Promises, making them easier to work with.

Now that we have learned about Promises and Fetch I will show you how we can rewrite a fetch statement using Async/Await.

So without Async/Await we use “.then” to wait on data to be returned. This is fine for simple requests, but when we are dealing with multiple promises it can get a bit confusing as to when each line will get executed.

With Async/Await we can write code that looks synchronous but is actually asynchronous.

The first thing that we must do is wrap our asynchronous code in a function. And we add the “async” keyword before the function. Now within the function we can create a response const and use the “await” keyword before our promise, which in this case is our fetch statement.

Note that you cannot use the “await” keyword without the “async” keyword attached to the function. These only work together.

The function itself can be a standard function, or it can be an arrow function, or even an anonymous function that calls itself.

So understanding how Promises and Async/Await work together can make your code cleaner and more logical.

I'll be releasing a new video every day in January! Stay tuned..
_____________________________________

📚 Learn to CODE in just a FEW months here:
_____________________________________

🛠️ Tools I use:

_____________________________________

💖 Show support!
_____________________________________

Watch Next:
_____________________________________

Connect With Me:
_____________________________________

** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.

#JavaScriptJanuary #31Days31Videos #codeSTACKr
Рекомендации по теме
Комментарии
Автор

Thanks for all of the support! Stay tuned for a new video every day in January!!

Watch the entire #JavaScriptJanuary series from the beginning!

📚 My Favorite Web Design Books 📚
Web Design with HTML, CSS, JavaScript and jQuery Set by Jon Duckett (paid link)

codeSTACKr
Автор

Loving the January videos. Keep up the good work!

mikeviverette
Автор

I knew what async and await was. But I didn't know the .then. So I still learned something. You are a pro!

bjornlive
Автор

I like async/await because I'm a stupid php programmer XD

NoahNobody