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?
伊谢尔伦2017-06-12 09:31:34
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.
学习ing2017-06-12 09:31:34
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.
function foo(){
|
| not accessible
|
let a = 1
}
PHP中文网2017-06-12 09:31:34
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