I know that JavaScript is an interpreted language, which doesn't have the benefits of code optimization that may be done for a compiled language.
So I was curious, which would be better to use?
A. With .length in the loop:
//Assuming 'arr' in an array of an arbitrary length
for(var i = 0; i < arr.length; i++)
{
//Do work on element arr[i];
}
B. or this:
//Assuming 'arr' in an array of an arbitrary length
var arrLen = arr.length;
for(var i = 0; i < arrLen; i++)
{
//Do work on element arr[i];
}