The create process of
let is promoted, but initialization is not promoted.
both creation and initialization of var have been promoted.
function's "create", "initialize" and "assign" have been promoted.
has been solved, no one answered this community too. Abandoned pit
"creation process is promoted, initialization is not promoted" is OK, but it is not in line with the official definition. Wouldn't it be better to directly follow the official explanation that "if there is no ascension, there is TDZ"? why do we have to rely on ascension?
of course not! It will be in a temporary dead zone, and you won't get the desired value until you initialize it.
neither let nor const will be promoted, just experiment with the following code:
console.log(bbbb); // undefined
var bbbb = 10;
console.log(aaaaa); // Uncaught ReferenceError: aaaaa is not defined
let aaaaa = 10;
console.log(cccc); // Uncaught ReferenceError: cccc is not defined
const cccc = 10;
say the result directly: there is a variable improvement.
but why does the following situation report an error:
function foo(){
console.log(_var);
const _var = '_var';
}
just because there is a temporary dead zone, it has nothing to do with whether the variable is promoted or not.
look at the picture and talk
variables defined by let and const are promoted, but they are not initialized, cannot be referenced, and do not have an initial value of undefined, as with variables defined by var.
when you enter the scope of the let variable, the storage space is created for it immediately, but it is not initialized.
variable assignment can be divided into three stages:
- create variables, open up space in memory
- initialize variables, initialize variables to undefined
- real assignment
about let, var and function:
- let's "creation" process is promoted, but initialization is not promoted.
- both creation and initialization of var have been promoted.
- function's "create", "initialize" and "assign" have been promoted.