var
keywords used to declare variables in ES5, no block-level scopes, variable elevation
Let
ES6, there is a block-level scope, there is no variable elevation, so if the first use of the declaration will appear temporary Dead zone
Const
ES6, there is a block-level scope, no variable ascension, the definition must be assigned an initial value, the variable point to the address can not be changed
another difference between the Var and let
Let cannot be defined as a global variable, that is, through window. cannot be accessed, but Var can.
Example 1: through var
var sum = 0 for
(var i = 0; i< i++) {
sum = sum + i
}
console.log (i)//*
Conso Le.log (window.sum)//
Console.log (this.sum)//
2: Through let
-let sum = 0 for (let
i = 0; i<) +) {
sum = sum + i
}
console.log (i)//undefined
console.log (window.sum)//undefined
Console.log (this.sum)//undefined