Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What will be the use of async keyword after the ES2022 release?

I am just curious, as per ES2022 release we can use top level await and that means we don’t need to use async keyword to use await, before es2022 release we were not allowed to write await without async.
So what will be the use of async keyword now? Is there are any other use cases where we can utilize async keyword?

Reference –
What’s new in JavaScript after the ES2022 release

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Top-level await does not replace async functions. You will still (and forever) be forbidden to do

const fn = () => {
  await callApi();
};

or anything more complicated than that, because await can only used in an async function – and permitting await on the top level doesn’t change that.

Functions are the building blocks of modular programming. Top-level await is only there to make the syntax a bit easier – it doesn’t fundamentally change the language or make functions obsolete.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading