The difference between let and const in es6 is: the variables declared by let can be changed, and both the value and type can be changed; while the constants declared by const cannot be changed, that is, once const is declared, it must be initialized immediately and cannot be changed later. Assign value again.
The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
The difference between let and const:
Variables declared by let Can be changed, both value and type can be changed (let: variables are declared);
const declared constants cannot be changed
This This means that once const is declared, it must be initialized immediately and cannot be assigned later.
const i ; // 报错,一旦声明,就必须立即初始化 const j = 5; j = 10; // 报错,常量不可以改变
The same points between let and const:
Both They can only be declared valid in block-level scope
and then used after the variable is declared.
There is no variable promotion, and there is a temporary dead zone
It cannot have the same value as other variables or functions in its scope Name
[Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of What is the difference between let and const in es6. For more information, please follow other related articles on the PHP Chinese website!