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