Hoisting, Closures, and the this Mystery

The famous var-in-loop bug, closures as private state, and why this means different things in regular vs arrow functions.

Step 1 of 8

Quick recap: TDZ

You learned about hoisting and the Temporal Dead Zone in Function Factory. Quick refresher:

  • var declarations are hoisted with undefined — accessing them early returns undefined, no error.
  • let and const are hoisted but in the TDZ — accessing them early throws a ReferenceError. This is a feature, not a bug — it surfaces mistakes early.
  • Function declarations are fully hoisted, body and all.

This lesson uses that as a stepping stone to two harder topics: closures and this.