JavaScript AcademyProfessional Engineering

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

  1. In Function declaration, notice the call works before the function's line.
  2. In var, step until stock changes from undefined to 12.
  3. 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.