1. Reading a var early
var a is hoisted and initialized to undefined, so reading it before assignment logs undefined rather than throwing.
console.log(a); // undefinedTyporithm · medium
Step 1 of 8 · intro card
Closures & Scope
var declarations hoist and initialize to undefined, so reading a var before its line yields undefined. let and const also hoist but stay uninitialized in the temporal dead zone, so reading them before the declaration throws a ReferenceError.
JavaScript moves declarations to the top of their scope before running code — this is hoisting. For var, the variable is also initialized to undefined, so an early read returns undefined instead of erroring.
let and const are hoisted too, but they are not initialized. From the start of the block until the declaration executes, the variable sits in the temporal dead zone (TDZ).
Touching a let or const variable inside its TDZ throws a ReferenceError. This is why let and const help catch use-before-declaration bugs that var would silently hide.
var hoists and initializes to undefined.
let and const hoist but stay uninitialized (the TDZ).
Reading a TDZ variable throws a ReferenceError.
console.log(a); // undefined
var a = 1;
console.log(b); // ReferenceError
let b = 2;Connect each part of the code to the concept before you type.
var a is hoisted and initialized to undefined, so reading it before assignment logs undefined rather than throwing.
console.log(a); // undefinedThe declaration is hoisted to the top of the scope; only the assignment to 1 happens here.
var a = 1;b is in the temporal dead zone until its let declaration runs, so accessing it throws a ReferenceError.
console.log(b); // ReferenceErrorThe TDZ for b ends here; only from this line onward can b be read or written.
let b = 2;Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.