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.
Doing a quick test (here and here) the difference seems insignificant to me. I would worry about the other aspects of
varvslet, 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...– hkotsubo
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!
– Paulo Rogério da Silva
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...
– hkotsubo