JSFiddle - React, Tailwind, and code Playground

by inser

JavaScript

var test = {    
  length: function() {
    document.write('length called<br />');    
    return 10000;
  }
}

console.time('test');

for(var i = 0; i < test.length(); i++)
{
  document.write('iteration ' + i + '<br />');
}
console.timeEnd('test');

document.write('--------------<br />');

console.time('test2');
var length = test.length();
for(var i = 0; i < length; i++)
{
  document.write('iteration ' + i + '<br />');
}
console.timeEnd('test2');