The difference between let, const and var in es6

1. let is a new way to declare variables in es6:
(1) scope is block-level scope
(2) there is no variable promotion;

(3) The definition cannot be repeated, otherwise an error will be reported

(4) There is a temporary dead zone (if quoted before the declaration, there will be a dead zone)

2、 const:

  Used to declare a constant, and the declared constant is not allowed to change (otherwise it will report an error), read-only attribute, so it must be assigned at the same time as the declaration. and let const, are block-level scope, the temporary presence of the dead zone, the variable declaration does not exist in advance, allowed to repeat the definition

3, var js method is used to declare variables before ES6, which is characterized by:
(. 1) var The scope of the function is the scope of the function, use var to declare a variable in a function, then this variable is only valid in this function

(2) There is a variable declaration in advance (although the variable declaration is advanced, but the variable assignment is not advanced, if the variable is used before the declaration, the value is undefined)

Guess you like

Origin www.cnblogs.com/xiao-lei-ge/p/12752009.html