Loops

In this section, we are going to learn efficient ways to create for loops in detail.

How loops affect performance

Loops are a very common way to iterate through large blobs of data or objects and iterating through each instance of a DOM object or a piece of data. Let's say we have a simple loop that generates a p paragraph tag and appends the page with an inner text value of the i integer in the loop, with a maximum limit of 9000. Let's take a look at the following code sample and see how this is done. I've created a simple HTML5 page with a script tag that includes the code on line 10, as shown next:

How loops affect performance

So, how is this code process-intensive? For ...

Get Mastering JavaScript High Performance now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.