Learning object 35 of 100
Hoisting and temporal dead zone explorer
Step through programs that use names before their declarations and see which work, which give undefined and which throw.
Loading…
What it shows
Before a scope runs, its declarations are registered. Function declarations are ready immediately, var variables start as undefined, and let, const and class are in the temporal dead zone until their line runs, so touching them early throws a ReferenceError.
Guided experiment
- In Function declaration, notice the call works before the function's line.
- In var, step until stock changes from undefined to 12.
- In TDZ, read the error message after the first step.
Predict
console.log(a); var a = 1; prints what?
Related
Lessons: Lesson 49: Hoisting and the temporal dead zone
Projects: Project 9: Shopping Cart Price Calculator
Source: web/assets/js/objects/object-035.js in the companion repository.