Ajay Yadav
Ajay Yadav

@ATechAjay

10 Tweets Mar 18, 2023
📢 A Complete Guide to Async and Await in JavaScript
A Thead🧵
📃 Table of content:
❍ Overview
❍ Synchronous VS Asynchronous
❍ async keyword
❍ await keyword
❍ A small project
❍ Overview
- Async and await is a feature in JavaScript that allows us to write asynchronous code that looks like synchronous code.
- Asynchronous programming is generally done using Promise or callback in JavaScript.
❍ Synchronous VS Asynchronous
- Synchronous code is executed line by line. If there is a task that takes a long time to complete, it blocks the execution of the program until that task is complete.
- However, asynchronous code is not executed line by line; instead, it is executed non-sequentially.
- That means an asynchronous code allows us to continue executing long-running tasks in the background while the next line of code is executed immediately after the long task.
❍ async keyword
- The async keyword is used to define a function as asynchronous that always returns a Promise.
- Or it alerts the JavaScript runtime that the function contains asynchronous code.
❍ await keyword
- The await keyword is used to halt or pause the execution of the async function until a Promise is resolved or rejected.
❍ A small project
In this code snippet, I am calling an API from the remote server using async and await.
Codepen link, plz open the console:)
codepen.io
That's all for now, we will meet in the next thread😍
🔔 Follow Me @ATechAjay
For:
🌐 Web Development
✨ JavaScript
⚛️ React JS
📝 Writing Skill
🔥 Motivation
💹 Growth
⛔ But Not For Only Resources & Shitpost 😁
Thank you so much for staying to the end of this thread💚

Loading suggestions...