Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaScriptcustom iterables Symbol.iteratorSingle-choice MCQ

An object's `[Symbol.iterator]` method `return this` and the iterator object itself defines `next`. After fully consuming it once with a `for...of`, what happens on a second `for...of` over the same object?

const it = { i: 0, next() { return this.i < 2 ? { value: this.i++, done: false } : { value: undefined, done: true }; }, [Symbol.iterator]() { return this; } }; for (const x of it) {} console.log([...it]);