A var, or Let or const has performance difference for several?

Asked

Viewed 208 times

2

I have seen numerous answers that say it’s just a matter of style, which is good practice due to Hoisting, but I wanted to know numbers (I don’t know how to get them) on the performance aspect. There is a performance difference amid:

var
fruta = 'banana',
pessoa = 'Maria',
acao = 'comer';

and

var fruta = 'banana';
var pessoa = 'Maria';
var acao = 'comer';

If there is a difference... does it keep using const and Let? If anyone can help me, I’d really appreciate it.

  • 1

    Doing a quick test (here and here) the difference seems insignificant to me. I would worry about the other aspects of var vs let, as scope, Hoisting, etc., because performance does not seem to be the problem in this case. And if the app is having performance issues, probably the bottleneck isn’t there...

  • wow, I didn’t know this benchmark site! Thanks! 15% slower didn’t seem like something so insignificant. Yes, in an application with few variables, this may not make much difference, but in a heavy application where each improvement makes a difference, I think it’s something else to consider. Nice to see the difference between immediate assign and late assign too. Thank you so much! Show!

  • 1

    I think these tests depend on the browser, because I only had differences less than 10%. Still, it would only make a difference if the script ran a million times, I don’t think that should be the biggest concern...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.