Hoisting
Hoisting
Section titled “Hoisting”Introduction
Section titled “Introduction”Hoisting is JavaScript’s behavior of moving declarations (but not assignments) to the top of their scope during the compilation phase.
Learning Objectives
Section titled “Learning Objectives”- Understand how
var,let,const, andfunctionare hoisted differently - Explain the Temporal Dead Zone (TDZ)
- Write code that avoids hoisting confusion
Visual Summary
Section titled “Visual Summary”flowchart TD A["JavaScript Code"] B["Compilation: Memory Allocation"] C["Execution"]
A --> B --> C
B --> D["function: Fully hoisted"] B --> E["var: Declared + initialized as undefined"] B --> F["let/const: Declared, NOT initialized (TDZ)"] B --> G["class: NOT hoisted"]Topics Covered
Section titled “Topics Covered”| Topic | Description | Est. Time |
|---|---|---|
| Function Hoisting | How function declarations are hoisted | 10 min |
| var Hoisting | How var declarations are hoisted | 10 min |
| let/const Hoisting | TDZ and block scoping | 15 min |
| Temporal Dead Zone | The TDZ explained in detail | 10 min |
Prerequisites
Section titled “Prerequisites”- Execution context basics
- Variable declarations with var, let, const
- Function declarations vs expressions
Learning Path
Section titled “Learning Path”Function Hoisting → var Hoisting → let/const Hoisting → Temporal Dead Zone