Let vs var performance

I read about ES6. Let the keyword vs the existing keyword var.

I have few questions. I understand that "showing" is the only difference between let and var, but what does that mean for the big picture?

function allyIlliterate() { //tuce is *not* visible out here for( let tuce = 0; tuce < 5; tuce++ ) { //tuce is only visible in here (and in the for() parentheses) }; //tuce is *not* visible out here }; function byE40() { //nish *is* visible out here for( var nish = 0; nish < 5; nish++ ) { //nish is visible to the whole function }; //nish *is* visible out here }; 

Now my questions are:

  • Does any memory (/ performance) advantage over var?

  • Besides browser support, what are the reasons why I should use let over var?

  • Can I start using let now over var in my code workflow?

Thanks R

+6
source share
1 answer

let is much slower than var in node.js. Version v6.3.0 in any case. This is sometimes dramatic. The code below is about three times slower if you replace var with let:

 function collatz() { var maxsteps = 0; var maxval = 0; var x = 1; var n; var steps; while (x < 1000000) { steps = 0; n = x; while (n > 1) { if (n & 1) n = 3*n + 1; else n = n / 2; steps += 1; } if (steps > maxsteps) { maxsteps = steps; maxval = x; } x += 1; } console.log(maxval + ' - ' + maxsteps + ' steps'); } collatz(); 
+5
source

All Articles