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:
vardeclarations are hoisted withundefined— accessing them early returnsundefined, no error.letandconstare hoisted but in the TDZ — accessing them early throws aReferenceError. 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.