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

An iterator object has a `next()` method but you cannot use it directly in a for-of loop. What single addition makes it work?

const it = { i: 0, next() { return this.i < 2 ? { value: this.i++, done: false } : { value: undefined, done: true }; } }; // for (const x of it) {} // currently throws: it is not iterable