Menu

Async/Await in JavaScript: Writing Cleaner Asynchronous Code
📰
0

Async/Await in JavaScript: Writing Cleaner Asynchronous Code

DEV Community·Anoop Rajoriya·about 1 month ago
#KG1nebPa
#why#how#error#comparison#async#await
Reading 0:00
15s threshold

If you ever lost youself forest of .then() or trapped in the callback hell then async/await is about to become you'r best friend. It introduced in ES2017, it's ofthen known as syntatic sugar because it does not change how javascript work under the hood, its only make it easier for us humans to read. Content List Why async/await was introduced How Async Functions Work The await Keyword Concept Error Handling with Async Code Comparison: Promises vs. Async/Await Why async/await was introduced Before the asyn/await , we handle asynchronous operation by callbacks and then promises were introduced. While promises were a massive upgrade but it have some issues: Chaining complexisty: long chaining of .then() become difficult to follow, especially when passing data between them. Verbosity: you had write a lot of boiler plate just to write a simple data fetch. Debugging: error handling with .catch() was something tricky and stack traces inside promises chain were not alway helpful.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More