Declaring variables inside loops

JavaScript performance comparison

Revision 10 of this test case created

Info

Tests whether declaring a variable inside a loop, rather than declaring outside and just assigning values, is more performant

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Declare in a loop with one statement

var items=[1,2,3,4];
for (var i = 0; i < 5; i++) {
  var x += items[i];
}
pending…
Declare outside loop
var i = 0;
var items=[1,2,3,4];
var x=0;
for (i = 0; i < 5; i++) {
  x += items[i];
}
pending…
Declare in a loop with multiple statements
var i = 0;
var items=[1,2,3,4];
var x=0;
for (var i = 0; i < 5; i++) {
  x += items[i];
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment