javascript - let declare variables
某草草
某草草 2017-06-12 09:29:34
0
3
823

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?

某草草
某草草

reply all(3)
伊谢尔伦

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.

学习ing

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
}
Ty80

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template