Scope
Definition
The 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.
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.
HoistingJavaScript'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).
ClosureA function that retains access to variables from its outer (enclosing) scope even after the outer function has returned. Closures are created every time a function is created in JavaScript.