let vs var performance
JavaScript performance comparison
Preparation code
<script type="application/javascript;version=1.7">
"use strict";
var firstarray = [];
for (var i = 0; i < 1000; i++) {
firstarray[i] = Math.floor(Math.random() * 11);
}
var secondarray = [];
for (var i = 0; i < 1000; i++) {
secondarray[i] = Math.floor(Math.random() * 11);
}
function doNoVar()
{
var resultarray = [];
for (var i = 0; i < 1000; i++) {
resultarray.push(firstarray[i] + secondarray[i] + 5);
}
}
function doVar()
{
var resultarray = [];
for (var i = 0; i < 1000; i++) {
var firstnumber = firstarray[i];
var secondnumber = secondarray[i] + 5;
var total = firstnumber + secondnumber
resultarray.push(total);
}
}
function doVar2()
{
var resultarray = [];
var firstnumber = 0;
var secondnumber = 0;
var total = 0;
var i;
for (i = 0; i < 1000; i++) {
firstnumber = firstarray[i];
secondnumber = secondarray[i] + 5;
total = firstnumber + secondnumber
resultarray.push(total);
}
}
function doLet()
{
let resultarray = [];
for (let i = 0; i < 1000; i++) {
let firstnumber = firstarray[i];
let secondnumber = secondarray[i] + 5;
let total = firstnumber + secondnumber;
resultarray.push(total);
}
}
function doLet2()
{
let resultarray = [];
let firstnumber = 0;
let secondnumber = 0;
let total = 0;
let i;
for (i = 0; i < 1000; i++) {
firstnumber = firstarray[i];
secondnumber = secondarray[i] + 5;
total = firstnumber + secondnumber;
resultarray.push(total);
}
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test  Ops/sec  

No var 

pending… 
Var 

pending… 
Var 2 

pending… 
Let 

pending… 
Let 2 

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:
 Revision 1: published
 Revision 3: published
 Revision 4: published
 Revision 5: published
 Revision 6: published
 Revision 7: published
 Revision 8: published
 Revision 9: published by Yazan Medanat
 Revision 10: published
 Revision 11: published
 Revision 12: published
 Revision 14: published
 Revision 20: published
 Revision 21: published
 Revision 23: published
 Revision 24: published
 Revision 25: published
 Revision 26: published
 Revision 27: published
 Revision 28: published
 Revision 29: published
 Revision 30: published by polpo
 Revision 31: published
 Revision 32: published
 Revision 33: published
 Revision 34: published by Gabriel
 Revision 35: published
 Revision 37: published
 Revision 38: published
 Revision 39: published
 Revision 40: published by noname
 Revision 41: published
 Revision 42: published
 Revision 43: published
0 comments
Comment form temporarily disabled.