Question discussion

What is the output of the following JavaScript code?async function f() { console.log(1); await null; console.log(2); } f(); console.log(3);

2588Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following JavaScript code?

async function f() {
  console.log(1);
  await null;
  console.log(2);
}
f();
console.log(3);
  • A1 2 3
  • B3 1 2
  • C1 3 2
  • D2 1 3
Correct answer: C

Explanation

f() runs synchronously up to the first await and prints 1; the rest of f is then queued as a microtask, so the main code prints 3 before 2 is printed.

Discussion 0

Nobody has replied yet. Start the discussion!