Title says it all.
Output is:
starting
lol
undefined
0 undefined
Expected:
starting // yield giving us back a string
lol // yield giving back result from bar()
'apples' // since the 'yield bar()' is 'replaced' by 'apples' via next('apples')
'0 apples' // the last yield should tell us what fruit is, but its undefined
Code:
const bar = () => 'lol'
function* foo1() {
yield 'starting'
let a = 0
let fruit = yield bar()
console.log(fruit) // <-- y no apples? I could even see 'lol' being here too.
yield `${a} ${fruit}`
}
let g = foo1()
console.log(g.next().value)
console.log(g.next('apples').value)
console.log(g.next().value)