codemarch
codemarch

@codemarch

11 Tweets 5 reads Sep 20, 2022
Javscript async/await
A Complete Guide:
Thread🧵
📌We use the async keyword with a function to represent that the function is an asynchronous function.
📌The async function returns a promise.
🎯For JavaScript Promises you can go through
📌The syntax of async function is:
⏺️name - name of the function.
⏺️parameters - parameters that are passed to the function.
📌Example: Async Function
📌In the above program, the async keyword is used before the function to represent that the function is asynchronous.
Since this function returns a promise, you can use the chaining method then() like this:
📌JavaScript await Keyword
The await keyword is used inside the async function to wait for the asynchronous operation.
⏺️The syntax to use await is:
📌The use of await pauses the async function until the promise returns a result (resolve or reject) value.
For example,
➡️In the above program, a Promise object is created and it gets resolved after 4000 milliseconds. Here, the asyncFunc() function is written using the async function.
➡️The await keyword waits for the promise to be complete (resolve or reject).
⏺️let result = await promise;
📌Hence, JavaScript is displayed only after promise value is available to the result variable.
📌In the above program, if await is not used, JavaScript is displayed before Promise resolved.
📝Note: You can use await only inside of async functions.
If you enjoyed reading this thread, please do the following:
1. Like the thread❤️
2. Retweet the first tweet.🔃
3. Follow me and enable notifications: ✅
@CodeMarch
Thank you for reading all the way through.
✨ JavaScript for Starters: The Complete Guide ✨
➱ JavaScript Roadmap 2022
➱ JavaScript Fundamentals with Exp.
➱ 50+ Programs to practice with Soln.
➱ 50+ Project Ideas
➱ 25+ Projects Code
Grab it NOW.
codemarch.gumroad.com

Loading suggestions...