---
title: "What do you understand by async and await."  
description: "What do you understand by async and await."  
author: "Nishi Tiwari"  
published: 2020-06-18  
updated: 2020-06-18  
canonical: https://www.mindstick.com/forum/155994/what-do-you-understand-by-async-and-await  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# What do you understand by async and await.

[Please describe](https://www.mindstick.com/interview/33713/please-describe-the-relationship-between-seo-and-sem) me in details what is [async and await](https://www.mindstick.com/forum/160101/describe-the-purpose-and-usage-of-the-async-and-await-keywords-in-modern-javascript) and when it is use with suitable images.

## Replies

### Reply by Nishi Tiwari

## 1. when should we use await?

We should use await before the async function call.

## 2. When should I use async?

We mark a function as an async one so that it can be called with the await keyword.

## OR

1. We can use await with any function that returns a promise. The function which we are awaiting doesn't need to be async necessarily.

2. We should use [**async functions when we want to use the await keyword**](https://www.mindstick.com/forum/155993/give-practical-ways-to-write-better-javascript) inside that function. If we are not gonna be using the await keyword inside a function then we don't need to make that function async.

3. async functions by default return a promise. That is the reason that we are able to await async functions.

- Whenever an async function called, it always returns a Promise.
- As far as our code it could be written like this -

```
const getUsers = (ms) => { // There is no  need to make this async
    return new Promise(resolve => setTimeout(resolve, ms));
};
// the function is async as you  need to use await inside it
export const  inindex = async (req, res) => {
    await getUsers(5000);
    res.json([
      {
        id: 1,
        name: 'John Doe',
      },
      { id: 2,
        name: 'Jane Doe',
      },
    ]);
};
```

We can await any promise in an async function. The code after the await will be executed after the promise that we are awaiting finished.

This is a great alternative to the JavaScript callbacks.

- The new async/await syntax allows us to still use Promises, but it mainly eliminates the needs for providing a callback to the chained then() methods.
- This callback , instead of returning directly from the asynchronous function, just like if it were a synchronous blocking function.

```
let value = await myPromisifiedFunction();
```

- When we are planning to use await in our function we should mark our function with async keyword (like in c#)

![What do you understand by async and await.](https://www.mindstick.com/mindstickforums/894947d6-f920-46f0-a4d8-bda6590e67e3/images/ee9a41f0-9db2-4754-b9d6-cb0e7b3f69af.png)\


---

Original Source: https://www.mindstick.com/forum/155994/what-do-you-understand-by-async-and-await

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
