Wrong confirmation ID
  • Email
  • Favorite
  • Download
  • Embed
  • Private Content

JavaScript Variable Performance

by Nicholas Zakas on Jan 21, 2009

  • 8,143 views

My talk at the January 21, 2009 Mountain View JavaScript Meetup about the performance of JavaScript variables relative to their position in the scope chain.

My talk at the January 21, 2009 Mountain View JavaScript Meetup about the performance of JavaScript variables relative to their position in the scope chain.

Accessibility

Categories

Tags

javascript performance variables js javascript scope optmization favourites site-performance misc - ipadnine

More...

Upload Details

Uploaded via SlideShare as Adobe PDF

Usage Rights

© All Rights Reserved

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel

2 Embeds 26

http://www.slideshare.net 25
http://translate.googleusercontent.com 1

Statistics

Favorites
16
Downloads
172
Comments
4
Embed Views
26
Views on SlideShare
8,117
Total Views
8,143

14 of 4 previous next Post a comment

  • aarontgrogg Aaron Grogg , Co-Founder, Director of Development at UX Test Kitchen @Albin
    In this method:
    for (var i=0; i < items.length; i++) {
    JS has to determine the length of items each and every loop.

    Instead, you can declare an additional variable, len, and then JS needs only to do a simple comparison of the two variables each and every loop:
    for (var i=0, len=items.length; ++i < len;) {

    Also note the use of ++i in the comparison versus i++ as the third parameter of the for loop. This is documented as a faster incrementing method by Paul Irish: http://paulirish.com/i/d9f0.png

    Happy coding,
    Atg
    2 years ago Reply
    Are you sure you want to Yes No
  • vjnrv vjnrv Variables 2 years ago Reply
    Are you sure you want to Yes No
  • nzakas Nicholas Zakas , Front End Engineer at Yahoo! Because property access in JavaScript is slow, and doing it each time through a loop is expensive. See my other presentation, Writing Efficient JavaScript. 2 years ago Reply
    Are you sure you want to Yes No
  • gueste0556d Albin At slide #3: Why is items.length marked? 2 years ago Reply
    Are you sure you want to Yes No
Post Comment
Edit your comment Cancel

JavaScript Variable Performance — Presentation Transcript