🈯const

⭐️ ES6 (2015)

(declaration) declares a local constant in block scope.

const

ReferenceError: cannot access '...' before initialization.

it's common to declare const using capital letters.

using typeof on lexical declaration (let/ const/ class) in its temporal dead zone will throw a ReferenceError.

// ⭐ 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 {}

Last updated