How to fix await is a reserved word error inside async function in JavaScript?

Sometimes, we want to fix await is a reserved word error inside async function in JavaScript.

In this article, we’ll look at how to fix await is a reserved word error inside async function in JavaScript.

How to fix await is a reserved word error inside async function in JavaScript?

To fix await is a reserved word error inside async function in JavaScript, we can use await before the function that returns a promise.

For instance, we write

const sendVerificationEmail = () => async (dispatch) => {
  await Auth.sendEmailVerification();
  // ..
};

to call Auth.sendEmailVerification which returns a promise.

We use await to wait for the returned promise to finish before we run the rest of the code in the sendVerificationEmail function.

Conclusion

To fix await is a reserved word error inside async function in JavaScript, we can use await before the function that returns a promise.