Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What runs first after await in JavaScript?

Do you know what will be the output of this code?

JavaScript
async function run() {
  console.log(1);
  await null;
  console.log(2);
}

run();
console.log(3);
Show answer and explanation

The answer is 1 3 2.

An async function runs synchronously until its first await. Then it pauses and control returns to the caller, which logs 3. The rest of run continues as a microtask.

Take the full quiz Next question →

More Promises & Async questions

  1. Why does an arrow function in setTimeout keep this?
  2. Why does a Promise run before setTimeout 0?
  3. What does an async function return in JavaScript?
  4. Is the Promise constructor callback synchronous?
  5. What happens when one promise in Promise.all rejects?

Related topics