reused var in for-loop

JavaScript performance comparison

Test case created by Brendan Baldwin


Just want to see if reassignment of a var declared once in the for () stanza beats out an explicit var declaration and assignment in the loop body.

Preparation code

var numbers = [];
for (var n = 0; n < 1000; ++n) {
  numbers[n] = n;

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
var in body
for (var n = 0, l = numbers.length; n < l; ++n) {
  var number = numbers[n];
reused var in for
for (var n = 0, l = numbers.length, number; n < l; ++n) {
  number = numbers[n];

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers


Comment form temporarily disabled.

Add a comment