How JavaScript Async Await Work

In this tutorial, we will learn how JavaScript Async Await works. Async-Awaits are a syntactical sugar code to deal with promises.

#javascript  #asyncawait 

What is GEEK

Buddha Community

How JavaScript Async Await Work
Ollie  Dietrich

Ollie Dietrich


How Async/Await Works in Javascript

Async/await is a new way to write asynchronous code.  Async/await is actually just syntax sugar built on top of promises. It makes asynchronous code look and behaves a little more like synchronous code.


Thumb Rules for async-await:
1. `async` functions return a promise.
2. `await` pauses the code execution within the `async` function.
3. There can be multiple `await` statements within a single `async` function.
4. `await` only pauses the code execution within the `async` function. It makes sure that the next line is executed when the promise resolves.


⌚ Timestamps:
00:00 Introduction
00:58 Async
02:27 Await

 #javascript  #async  #await 

Javascript : Async Await in Javascript | Javascript Interview questions.

Explained in detail about

  • Async
  • Await
  • Fetching country data using Async & Await
  • How Async & Await better than promise

Dont miss to watch the video & ask your questions or doubts in comments

#javascript #async #await

Sadie  Cassin

Sadie Cassin


How To Use Async/Await in JavaScript

How To Use Async/Await in JavaScript



The async and await is keywords to perform the promise-based asynchronous operation. In this article, we are going to learn how to use async/await in JavaScript.

How to use Async?

It is mandatory to define the async keyword before any function that turns your normal function to async function. Let’s start to learn it through a very basic example.

Normal Function Example

function sayHello() {
    return 'Hello World!';

sayHello(); // Hello World!


Async Function Example

async function sayHello() {
    return 'Hello World!';

sayHello(); // [object Promise] { ... }


We could explicitly return a promise with Promise.resolve() like:

async function sayHello() {
    return Promise.resolve('Hello World!');
async function sayHello() {
    return 'Hello World!';

let greeting = sayHello();
greeting.then((value) => console.log(value)); // Hello World!


or you can try this:

async function sayHello() {
    return 'Hello World!';

sayHello().then((value) => console.log(value) ); // Hello World!

#javascript #async #await

Giles  Goodwin

Giles Goodwin


Understanding JavaScript: Promises, Async & Await!!


We all know the importance of promises in our life. We even have a special day dedicated to it :) But how well do we know the importance of promises in JavaScript? Well if you don’t know it yet, it’s a great time to know it because they are becoming more and more popular. So what are promises? Let’s try to understand it through an analogy.

Suppose you are a top class rapper and you haven’t released an album for a while and fans are asking for it day and night. So what you do is that you “promise” them that whenever it will be out, all of them would be notified. To get this done you give your fans a list. They can fill in their email addresses, so that when the album becomes available, all the subscribers instantly receive it. And even if something goes wrong, say a pandemic, so that you can’t release the album, they will still be notified.

Now everyone is happy: You, because the people don’t crowd you anymore, and fans, because they won’t miss any news on the album.

This is a real-life analogy for things we often have in programming:

  1. “producing code” that does something and may take time. That’s a “rapper”.
  2. “consuming code” that wants the result of the “producing code” once it’s ready. Many functions may need that result. These are the “fans”.
  3. A promise is a special JavaScript object that links the “producing code” and the “consuming code” together. In terms of our analogy: this is the “subscription list”. The “producing code” takes whatever time it needs to produce the promised result, and the “promise” makes that result available to all of the subscribed code when it’s ready.

JavaScript promises are much more complex than a simple subscription list: they have additional features and limitations. But it’s fine to begin with.

#async #promises #javascript #development #await

Javascript async-await: How to Use ES7 async-await

Javascript async-await feature is used to deal with asynchronous code in javascript. The async-await is a just new technique to write async code in a sync function manner.  You can write it as a simple synchronous function. That makes it very popular and understandable. Node.js is now supporting async-await out of the box.

Async-await is a new way to write asynchronous code. Previous options for asynchronous code are  callbacks and  promises. Async/await built on top of promises. It cannot be used with plain callbacks or node callbacks.


You can read the following tutorials if you do not know anything about Javascript callbacks and promises.

Promises In ES6

Callback in Javascript

#javascript #node.js #async/await