let will not have variable promotion; if I use let before declaration, the browser should report an error; but my printout is undefined; is it my understanding or my writing error?
ErrorUncaught ReferenceError: a is not defined means the variable is undefined, not that the variable is undefined. If the value of the variable variable is undefined, then console.log(variable) should output undefined and should not report an error.
Variables declared by let and const will not be declared in advance, which means that the variables are not accessible before the runtime execution context is lexically bound.
The first line prints. When printing, because it is let, not define because it is not improved. The second line, let xxx, is not written, which should also be the error
If it is var, it is undefined Because there is a promoted variable but it is not specified or copied
Error
Uncaught ReferenceError: a is not defined
means the variable is undefined, not that the variable isundefined
. If the value of the variablevariable
isundefined
, thenconsole.log(variable)
should outputundefined
and should not report an error.Variables declared by let and const will not be declared in advance, which means that the variables are not accessible before the runtime execution context is lexically bound.
The second line of code here makes no sense
The first line prints. When printing,
because it is let, not define because it is not improved.
The second line, let xxx, is not written, which should also be the error
If it is var, it is undefined
Because there is a promoted variable but it is not specified or copied