Hoisting
Definition
JavaScript's behavior of moving variable and function declarations to the top of their scope before code execution. `var` declarations are hoisted and initialized to `undefined`, while `let` and `const` are hoisted but not initialized (temporal dead zone).
Code Example
Learn More
Related Terms
A named container that stores a value in memory. JavaScript uses let, const, and var to declare variables. let and const are block-scoped, while var is function-scoped.
ScopeThe region of code where a variable is accessible. JavaScript has global scope, function scope, and block scope. Block scope was introduced with let and const in ES6.
Temporal Dead ZoneThe period between entering a scope and the point where a let or const variable is declared. Accessing the variable during this period throws a ReferenceError. This prevents bugs caused by using variables before they are initialized.