DEV Community

Ragul
Ragul

Posted on

Hoisting

Hoisting is JavaScript's default behavior of setting aside memory for variable and function declarations before your code actually runs line-by-line.

​It creates the illusion that declarations are physically "hoisted" (lifted) to the top of your code, though your source code isn't actually moved anywhere.

When JavaScript runs your code, it does so in two distinct phases inside the Execution

  1. Memory Allocation Phase (Phase 1): The engine scans the code and stores variable and function declarations in memory.

  2. Code Execution Phase (Phase 2): The engine executes your code line-by-line, assigning values and invoking functions.

Top comments (0)