liveBook · Manning

For...of

The JavaScript for...of statement iterates over successive values produced by an iterable's iterator.

How 2 Manning books explain it

Secrets of the JavaScript Ninja, Second Edition

A JavaScript loop that iterates over iterable values using the iterator protocol.

How it is used
Consumes generator-produced sequences without manual iterator control.
How deep it goes
Explains next() results through value and done, then characterizes for...of as shorthand for iterator control.
Examples
Uses WeaponGenerator to yield weapons and a warrior generator that delegates to a ninja generator.
What you can do after
Apply it to consume values yielded by a generator without writing iterator-control code.

Read how Secrets of the JavaScript Ninja, Second Edition explains for...of →

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

A JavaScript looping statement that iterates over iterable values by repeatedly obtaining successive items from an iterator.

How it is used
Processes iterable values one at a time, including values in arrays, strings, Sets, and Maps.
How deep it goes
Defines value iteration, compares it with for...in and forEach, and demonstrates early exit and generator use without detailing iterator internals.
Examples
Contrasts object-key and array-value loops, then uses nested loops to create a card deck from suits and faces.
What you can do after
Apply it to process iterable values, stop early with break, or yield values from a generator loop.

Read how Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond explains for...of →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.