The difference between const, let, var
Similarities : Both can be used to define variables.
Similarities and differences:
1. const and let have block-level scope, but var does not.
eg:
{
let a = 10;
}
console.log(a) //(报错:)Uncaught ReferenceError: a is not defined
//------------------------------------------------------------------
{
const a = 10;
}
console.log(a) //(报错:)Uncaught ReferenceError: a is not defined
//------------------------------------------------------------------
{
var a = 10;
}
console.log(a) //10
2. Var promotes variables. const and let do not.
3. The value of const-defined variables cannot generally be modified, but if the assigned value is a reference type, it can be modified because its address has not changed.