Loops in JS
JavaScript has many ways to loop over data structures, depending on what you plan to do with the data inside it, the size of a data structure, as well as the type of data strucutre. In this chapter you'll learn the various ways to execute loops in JS:
for
statement in JS: Explicit counters, iterations, step sizes and performance considerationsbreak
andcontinue
statements in JS: Exiting for loops and iterations prematurely- Label statements in JS loops: GoTo a specific point in the workflow of a JS loop
while
anddo while
statements: Loops that run with one expressionfor in
statement: A loop for key-value data structuresfor of
statement: Iterable and iterator protocols, plus what are and how to make iterable objects- Generators and yield expressions in JS: Functions that operate with iterable objects
Tip Certain JS data types have built-in methods that produce the same outcome as loops withfor
,while
,do while
and inclusivelyfor in
statements, but with simpler syntax: