CodeNewbie Community 🌱

Cover image for  An Ultimate Guide to Async/Await in JavaScript
Roshane
Roshane

Posted on

An Ultimate Guide to Async/Await in JavaScript

We all know that JavaScript is Synchronous which means that it has an event loop that allows you to queue up an action.
But there’s a lot of functionalities in our program which make our code Asynchronous.

One of them is the Async/Await functionality.

Async
It operates asynchronously via the event loop. Async functions will always return a value.

It makes sure that a promise is returned and if it is not returned then JavaScript automatically wraps it in a promise which is resolved with its value.

Async Function Snippet

Await
Await function is used to wait for the promise.
It could be used within the async block only.
It makes the code wait until the promise returns a result.
It only makes the async block wait.

Await Code Snippet

Notice that the console prints 2 before the β€œHello World”. This is due to the usage of the await keyword.

Supported Browsers: The browsers supported by Async/Await Function are listed below:

πŸ‘‰ Google Chrome
πŸ‘‰ Firefox
πŸ‘‰ Apple Safari
πŸ‘‰ Opera

Thank you for reading!

Hey, I'm Roshane πŸ‘‹
I tweet daily on JavaScript, Web Development, and Developer Resources.

If you found this thread useful
πŸ‘‰ Follow me (kendrip_) βœ…
πŸ‘‰ Retweet it πŸ”
πŸ‘‰ Leave a like πŸ’™

Thank you for the support fellow developers!

Top comments (0)