Engrain by ByteRush

JS.07.05 Mid-level

Iterators and generators

Comes up in: JavaScript, Coding

This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.

What it covers

  • iterator protocol (next, done)
  • iterables
  • for…of, spread use them
  • generator functions, yield, yield*
  • lazy sequences
  • return() and cleanup
  • Iterator helpers (map, filter, take on iterators)

Words you will know

iteratoriterablegeneratorlazy evaluation

What you will practise

  • range generator
  • lazy take/filter

Interview questions this answers

  • What is a generator? Give a real use case.
  • What is the iterator protocol?