code with 'let' will be more optimized than 'var' as variables declared with var do not get cleared when the scope expires but variables declared with let does.
var and let are both used for variable declaration in javascript but the difference between them is that var is function scoped and let is block scoped. Variable declared by let cannot be redeclared and must be declared before use whereas variables declared with var keyword are hoisted.
Let and const are both safer than var—there's no way to accidentally declare a global variable.
The execution context underlying how the JavaScript interpreter runs the code is basically the same when you use var compared to when you use let and const . That results in the same execution speed.
I've been reading about ES6 Let keyword vs existing var keyword.
I've got few questions. I understand that "scoping" is the only difference between let and var but what does it 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:
Does let posses any memory(/performance) advantage over var?
Other than browser support, what are the reasons why i should be using let over var?
Is it safe to start using let now over var in my code workflow?
Thanks, R
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With