What is the output of the following? “`js async function* asyncGen() { yield 1; yield 2; } async function run() { const gen = asyncGen(); console.log((await gen.next()).value); console.log((await gen.next()).value); } run(); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following? “`js async function* asyncGen() { yield 1; yield 2; } async function run() { const gen = asyncGen(); console.log((await gen.next()).value); console.log((await gen.next()).value); } run(); “`

Key points

  • The async generator function yields values sequentially.
  • The `run` function uses `await` to get the values from the generator.
  • Each `next()` call retrieves the next value in the sequence.

Ready to go further?

Related questions