What is the difference between "let" and "var"?
@lebyy▲ 0 net votes
Problem: ECMAScript 6 introduced the let declaration keyword . I've heard that it's described as a local variable, but I'm still not quite sure how it behaves differently than the var keyword. What are the differences? When should let be used instead of var ? Fix (from the top answer): Scoping rules The main difference is scoping rules. Variables declared by var keyword are scoped to the immediate function body (hence the function scope) while let variables are scoped to the immediate enclosing block denoted by { } (hence the block scope). function run() { var foo = "Foo"; let bar = "Bar";…