Ask HN: JS's for-of loop conceptually flawed, or is it just me? When working with generators, two identical for-of loops don't show the same behaviour.
Specifically, the first one will behave as expected, whereas the second one will terminate immediately.
What is this? I know that the iterator `g` will signal the value `done` after the first loop, but this behaviour was unexpected and really counterintuitive to me Note: contrary to this example, for-of loops of arrays will work as I expected. It just doesn't make sense Code example: > function* gen() { yield* [1,2,3] } undefined > let g = gen() undefined > for (let el of g) console.log(el) 1 2 3 undefined > for (let el of g) console.log(el) undefined edit: layout |