let
es6 grammar
let
Scope is block level, i.e., in the range {}If the variable is not declared on the use of the words being given ReferenceError , but
var
it will error undefined (variable does not exist upgrade)As long as there is scope block-level
let
commands, variables declared it would "bind" in this area, no longer subject to external influences. In the code blockslet
before the command to declare variables, the variables are not available. This is syntactically (temporary dead zone)var tmp = 123; if (true) { tmp = 'abc'; // ReferenceError let tmp; }
where
- JavaScript standard wording, var scope to only the local and global variables
const
- const and let the scope of the same, but once assigned a const can not be changed, just the first reference can not be changed, but the value of a variable or can be changed.