Declaring variables inside loops

JavaScript performance comparison

Revision 2 of this test case created by jordow


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
for (var i = 0; i < 1000; i++) {
  var x = 1, y = 2, z = {}, a = {};
Declare outside loop
var x, y, z, a, i;
for (i = 0; i < 1000; i++) {
  x = 1;
  y = 2;
  z = {};
  a = {};

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment