❗accessing var before declaration gets undefined❗️
JS ⟩ variable ⟩ var ⟩ access before declaration gets "undefined"
(unexpected result)
var has no temporal dead zone, but accessing it before its declaration will get undefined, instead of its initial value (if exists)❗
// ❗ "var" has no "temporal dead zone",
// but it's `undefined` initially.
// ⭐️ access before declaration ╭── ⭐️ ───╮
log(aVar, typeof aVar); // ❗ undefined, 'undefined'
// ┌─────────────────┐
// │ var declaration │
// └─────────────────┘
// ⭐️ access after declaration
var aVar = 'hello';
log(aVar, typeof aVar); // ❗ "hello", 'undefined'
Last updated
Was this helpful?