O'Reilly logo

Mastering JavaScript High Performance by Chad R. Adams

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required