The For Loop

Learn the basics of the for loop and how to use them in JavaScript.

We'll cover the following

You’ll often need to write loops with conditions that are based on the value of a variable updated in the loop body, like in our example. JavaScript offers another loop type to account for this: the for loop.

Example

Here’s the same program as above written instead with a for loop. It gives exactly the same result.

Get hands-on with 1200+ tech skills courses.