0k. This is not particular to javascript but applies to all languages. Consider an array of 10,000 items.
Normally, a for loop will go like following:
var largeArray; // // this array has 10,000 items
for( var i=0; i < largeArray.length; i++)
{
//do something
}
In above case javascript has to calculate length of array in each iteration and then check the
termination condition. It will be far more efficient if we calculate length of array before loop,
store it in a local variable and use this local variable for comparison.
var largeArray; // this array has 10,000 items
var l = largeArray.length;
for( var i=0; i < l; i++)
{
//do something
}
This will save javascript from calculating the array length in each iteration and will be faster.
Thanks...
|
My Blog Title
|