Why Async/Await Is Better Than Promise.then()

Why Async/Await Is Better Than Promise.then()

Maxim Orlov

1 год назад

559 Просмотров

Why should you use async/await if you can just use Promise.then() syntax instead? We'll examine two situations where async/await truly excels at asynchronous code. By the end of this video, you will understand why JavaScript developers love async/await and how it improves the readability of your code.

This video lesson is part of the Practical Async/Await course. Check it out! 👇

⏳ Practical Async/Await
https://maximorlov.com/practical-async-await/

👨‍💻 Code
https://github.com/Maximization/practical-async-await/tree/main/04-why-async-await-is-better-than-promisethen

👋🏼 Places I hang out
Website ☞ https://maximorlov.com
Twitter ☞ https://twitter.com/_maximization
Github ☞ https://github.com/Maximization
Dev.to ☞ https://dev.to/maximization
LinkedIn ☞ https://www.linkedin.com/in/maximorlov/

🎞 Timestamps
00:00 - Confusing order of execution
00:37 - Problem #1: Accessing variable later in the chain
01:35 - Extracting variable to outer scope
02:14 - Nesting promise chain
02:38 - Refactoring to async/await
03:15 - Problem #2: Async function inside if statement
04:10 - Using async/await

Тэги:

#async #await #async/await #javascript #nodejs #asynchronous #promise #promises #then() #syntax
Ссылки и html тэги не поддерживаются


Комментарии: