declares a block-scoped local variable.
Last updated 2 years ago
JS โฉ variable โฉ let
JS โฉ declaration โฉ variable โฉ let
โญ๏ธ ES6 (2015)
(declaration) declares a local variable in block scope.
โ ReferenceError: cannot access '...' before initialization.
typeof let/const/class in TDZ gets an errorโ๏ธ
โglobal let shadows global object propertyโ
โ let redeclaration not allowed even in sloppy modeโ๏ธ
โ let can't shadow parameter even in sloppy modeโ๏ธ
let is
a contextual keyword,
not reserved wordโ
JS is lenient with var, strict with let.
var redeclaration applied even in strict modeโ๏ธ, even in strict modeโ
let redeclaration not allowed even in sloppy modeโ๏ธ, even in sloppy modeโ
้่ชชไผผไนๆไธๅๅฅๆช็ "for-init" scope๏ผไฝ่ฃก้ข let ่ฎๆธ็่กจ็พๅ ถๅฏฆๆดๅๆฏ block-scopedใ๐ scopes matter with closures โฉ
โ๏ธconst / var
โtemporal dead zoneโ
โvar can shadow parameter even in strict modeโ๏ธ
โvar redeclaration applied even in strict modeโ๏ธ
YDKJS: Scope & Closures (v.2) โฉ Ch. 3: The Scope Chain
Statements and declarations โฉ declaring variables โฉ let