What is the output of the following? “`js function* gen() { yield 1; yield 2; return 3; } const g = gen(); console.log([…g]); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following? “`js function* gen() { yield 1; yield 2; return 3; } const g = gen(); console.log([…g]); “`

Key points

  • The spread operator `...` is used to convert the generator object into an array.
  • Only the yielded values are included in the array.
  • The `return` statement in the generator function does not affect the output.

Ready to go further?

Related questions