Member-only story

Async and Await in javascript

krishankant singhal
4 min readApr 22, 2020

--

Async and await are extension of promises in javascript. if you are not clear about promises, please go through my other tutorial.

async can be declared with function only and await can be used inside async function only.

From Mozilla website

async function declaration defines an asynchronous function — a function that is an AsyncFunction object. Asynchronous functions operate in a separate order than the rest of the code via the event loop, returning an implicit Promise as its result. But the syntax and structure of your code using async functions is much more like using standard synchronous functions.

So Basically

  1. The function operates asynchronously via event loop.
  2. It uses an implicit Promise to return the result.
  3. The syntax and structure of the code is similar to writing synchronous functions.

Further Mozilla document says

An async function can contain an await expression that pauses the execution of the async function and waits for the passed Promise's resolution, and then resumes the async function's execution and returns the resolved value. Remember, the await keyword is only valid inside

--

--

krishankant singhal
krishankant singhal

Written by krishankant singhal

Angular,Vuejs,Android,Java,Git developer. i am nerd who want to learn new technologies, goes in depth.

No responses yet