Global scope: var block-level scope: let const
First, the global scope
1. The outermost layer functions and variables in the outermost layer has a function of global scope defined
2. All the end of the definition of direct assignment of variables are automatically declared to have global scope
Second, the local scope
Variables declared inside a function belonging to a local variable, only local scope, external inaccessible.
It may cause two problems:
(1) an inner layer may cover the outer variable variable (variable lift) (2) for counting loop variable leak as a global variable (the example does not)
Third, the block-level scope
Let const variable declared valid in the current block region
Let const variable is defined by the function can not be output, there is no variable lift
To variable in order to use (not defined) in the statement
let const and can not be declared under the same scope variables of the same name
Variables declared const value must not be changed (except for composite type data)