The let variable can only be available inside the scope it's declared, they are scoped to the immediate enclosing block denoted by { }
The var variable belongs to the global scope or the local scope if they are declared inside a function.
There's also a difference when creating global properties.
Example:
var foo = "I'm added to the global obj as a property.";
console.log(window.foo); / /I'm added to the global obj as a property.
let foo = "I'm not added to the global obj as a property."
console.log(window.foo); // undefined . .
The main difference is the scope rules:
The let variable can only be available inside the scope it's declared, they are scoped to the immediate enclosing block denoted by { }
The var variable belongs to the global scope or the local scope if they are declared inside a function.
There's also a difference when creating global properties.
Example:
need an explanation for this answer? contact us directly to get an explanation for this answer