I'm trying to learn about generator functions in javascript and am experimenting with using a for..of loop in order to iterate over my yield statements. One thing I noticed is that the function terminates after the final yield statement and does not attempt to execute the return statement. If I were to create a generator object and call generator.next() 4 times, the return statement would trigger and we would see the associated generator object. Would anyone have any idea what's going on under the hood to cause this behavior?
Thanks!
function* generator(){
yield 1
yield 2
yield 3
return "hello there"
}
for (const value of generator()){
console.log('value', value)
}
doneinforamation, read the doc!