JavaScript Hoisting

द्वारा admin , 4 अप्रैल, 2026

Hoisting is JavaScript's default behavior during the compilation of moving declarations to the top of their scope before execution.

What exactly gets hoisted?

1. Variable declarations

  • var → hoisted and initialized with undefined
  • let & const → hoisted but not initialized (Temporal Dead Zone)

2. Function declarations

  • Fully hoisted (you can call them before declaration)

3. Class declarations

  • Hoisted but behave like let/const (TDZ applies)

Important: Only the declaration is hoisted, not the initialization