This solution is generated by ChatGPT, correctness is not guaranteed. You might also be able to find a solution fromcommunity posts.
AI solution for JavaScript Quiz on BFE.dev
71. two-way generator
The code outputs:
undefined
100
undefined
Explanation:
generator.next().value
calls the generator without passing any value. This means the firstyield
statement evaluates toundefined
, andconsole.log
outputsundefined
.generator.next(1).value
passes1
as the value for the firstyield
statement. This evaluates to100
, andconsole.log
outputs100
.generator.next(1).value
tries to pass another value to the generator, but there are no moreyield
statements to be evaluated. This means the function simply ends and outputsundefined
.