Hoisting
Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their scope; var and function declarations are hoisted.
Purpose
Understand the hoisting behavior of JS variable and function declarations, avoiding references to uninitialized variables.
Mechanism
var declarations are hoisted but assignments are not (value is undefined). function declarations are hoisted entirely (usable). let/const declarations are hoisted but enter the temporal dead zone (TDZ) and throw if accessed before initialization.
Use cases
- JavaScript understanding
- Debugging
- Code style