🈯const
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS ⟩ declaration ⟩ variable ⟩ const
(declaration) declares a local constant in block scope.
const
must have an initial value❗ (👉 more)
can't be reassigned❗ (👉 )
can't be ❗
⛔ ReferenceError: .
caused by referencing a / / in its ❗
using on (/ / ) in its will throw a .
replit:
// ⭐ temporal dead zone (start)
// ------------------------------
typeof aLet; // ⛔ ReferenceError: Cannot access 'aLet' before initialization
typeof aConst; // ⛔ ReferenceError: Cannot access 'aConst' before initialization
typeof aClass; // ⛔ ReferenceError: Cannot access 'aClass' before initialization
typeof undeclared; // ❗ 'undefined'
// ⭐ lexical declarations (let/const/class)
// --------------------------------------------
let aLet; // ⭐ initialized to `undefined`
const aConst = "hello";
class aClass {}