Let vs Var
Before the 6th edition of the ecmascript specification in javascript you could only
declare function-scoped variables with var.
let allows to declare block-scoped variables.
| let | var | |
|---|---|---|
| scope | block | execution context |
| visibility | after declaration | hoisted |
| can add property to global object | no | yes |
| redeclaration | SyntaxError | works |
| use before init (R-Value lookup) | Error(Temporal Dead zone) | undefined (declaration is hoisted) |
| typeof before decl (L-Value lookup) | Reference Error(Temporal Dead zone) | undefined(declaration is hoisted) |