SlideShare is now on Android. 15 million presentations at your fingertips.  Get the app

×
  • Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
 

JavaScript Variable Performance

by Front End Guy at Box on Jan 22, 2009

  • 10,783 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.

Statistics

Views

Total Views
10,783
Views on SlideShare
10,727
Embed Views
56

Actions

Likes
18
Downloads
186
Comments
4

4 Embeds 56

http://www.linkedin.com 28
http://www.slideshare.net 25
http://localhost 2
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via SlideShare as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

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
    3 years ago
    Are you sure you want to
    Your message goes here
    Processing…
  • vjnrv vjnrv Variables 4 years ago
    Are you sure you want to
    Your message goes here
    Processing…
  • nzakas Nicholas Zakas, Front End Guy at Box Because property access in JavaScript is slow, and doing it each time through a loop is expensive. See my other presentation, Writing Efficient JavaScript. 4 years ago
    Are you sure you want to
    Your message goes here
    Processing…
  • gueste0556d Albin At slide #3: Why is items.length marked? 4 years ago
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

JavaScript Variable Performance JavaScript Variable Performance Presentation Transcript