DEV Community

Discussion on: Using Python range() in JavaScript

Collapse
 
lionelrowe profile image
lionel-rowe

What you get with a generator function is basically what you hand-rolled with return { value, done }:

const gen = (function*() { yield 1 })()
// Object [Generator] {}
gen.next()
// { value: 1, done: false }
gen.next()
// { value: undefined, done: true }
Enter fullscreen mode Exit fullscreen mode

They're pretty nifty 😊