nextRound
TechnologiesCoding ProblemsBookmarksLearning Paths
nextRound
TechnologiesCoding ProblemsBookmarksLearning Paths
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

TOPIC OVERVIEW

javascript/Iterator and Generator

Lazy, pausable functions that let JavaScript produce values on demand — one at a time.

10 QuestionsAdvancedHigh Priority ~12 min read

Most JavaScript functions run start to finish and hand back a single value. Generators don't. A function marked with function* can pause itself mid-execution at every yield, hand control back to whoever called it, and pick up exactly where it left off the next time you ask for a value. That's the core trick: instead of computing a whole sequence up front, a generator computes it lazily, one step at a time, only when something actually asks for the next item.

Iterators are the protocol underneath all of this. Any object that implements a next() method returning { value, done } is an iterator, and any object with a Symbol.iterator method that returns one is iterable — which is exactly what powers for...of, spread syntax, and destructuring under the hood. Generators are just the easiest way to build an object that satisfies that protocol without writing the state machine by hand.

What you'll walk away knowing

The exact shape of the iterator protocol: next(), { value, done }, and Symbol.iterator
How yield pauses execution and resumes with a value passed back into the generator
Why generators are a natural fit for infinite sequences and lazy data pipelines
How yield* delegates to another iterable, and how async generators extend the same protocol to for await...of
1What is the Iterator Protocol in JavaScript? What two things must an object implement to be a valid iterator?Intermediate2What does Symbol.asyncIterator do? How does for await...of use it?Intermediate3Can you chain or compose custom iterators? Implement a map and filter for a custom iterator without converting to an array.Intermediate4How does Array.from() use the iterator protocol? What's the difference between passing an iterable vs an array-like object?Intermediate5How would you implement an infinite iterator (e.g., an infinite counter)? How do you safely consume it?Intermediate6How do Map, Set, Array, and String expose their iterators? Are they the same object or different?Intermediate7Implement a take(n) utility that takes the first n values from any iterable — including infinite ones:Intermediate8What happens if you forget to return { done: true } in a custom iterator? What are the consequences?Intermediate9What is a 'lazy' iterator and why is it important for performance? Give a practical example.Intermediate10What are Iterator Helpers (.map(), .filter(), .take(), .drop() on iterators natively)? What stage are they at in the TC39 proposal pipeline?Intermediate11What does Symbol.iterator do? How would you make a plain object iterable from scratch?Intermediate12What is the difference between map.keys(), map.values(), and map.entries()? What do they return?Intermediate13What is the difference between an iterable and an iterator? Can something be both?Intermediate14How would you implement a reusable iterable (one that can be iterated multiple times)?Intermediate15What is the difference between a regular iterator and an async iterator? What protocol does an async iterator follow?Intermediate16What built-in JavaScript data structures are iterable by default? How does for...of work under the hood with them?Intermediate17How would you implement a readable stream as an async iterable in Node.js?Intermediate18How does destructuring and spread (...) use the iterator protocol internally?Intermediate19What does yield* do? How is it different from a regular yield?Intermediate20What is a generator function? How is it different from a regular function in terms of execution flow?Intermediate21Explain generator.return(value) and generator.throw(error). When would you use each in production?Advanced22How would you use a generator to implement a tree traversal (DFS) without recursion stack concerns?Intermediate23Can you pass a value into a generator using .next(value)? How does that work and what is the practical use case?Intermediate24How do generators compose? Implement a pipeline of generator-based transformations (like RxJS operators but synchronous).Intermediate25When would you choose a generator over returning an array? What are the memory trade-offs?Intermediate26How do generators handle errors? How does .throw() interact with try/catch inside a generator?Intermediate27Explain what yield does. What does calling .next() return before and after a yield?Intermediate28What happens to a try/finally block inside a generator when .return() is called externally?Advanced29What are the pitfalls of using for await...of with an async generator that makes network calls? How do you handle errors and cancellation?Advanced30What are the debugging challenges with generators (e.g., in stack traces and async flows)? How do you mitigate them?Advanced31How would you implement Promise-based async/await using generators and a runner function? (This is essentially how Babel transpiled async/await early on.)Advanced32Are generators lazy? How do they differ from eager evaluation with arrays in terms of memory and performance?Intermediate33In a data pipeline processing millions of records, how would you use generators to avoid loading everything into memory?Intermediate34How would you use a generator to implement redux-saga-style side effect management? What makes generators a good fit for this?Advanced35Implement an async generator that fetches paginated API data, yielding one page at a time:Intermediate36How can generators be used to implement coroutines or cooperative multitasking in JavaScript?Intermediate37What is the difference between yield and return inside a generator?Intermediate38What are the limitations of generators? What problems are they not a good fit for?Intermediate
All Topics
1
Basics
Data Types
Functions
Objects
2
Engine
JIT
V8
Event Loop and Runtime
Concurrency and Threading
Bytecode and Parsing
Execution Context
Garbage Collector
3
this
Call Apply Bind
Closure
Error Handling
4
String Operations
Array Operations
Iterator and Generator
Modules
5
Events
Promises
Web Workers
Web Sockets
6
Functional Programming
Currying
Higher Order Functions
Memoisation
7
ES6 Classes
ES6
PWA
Web Assembly
Browser APIS
8
Security
Code
Polyfills
Sharethis topic

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.