Const vs Let vs Var
Definition
`const` declares a block-scoped, read-only reference (the value itself can still be mutated for objects/arrays). `let` declares a block-scoped, reassignable variable. `var` declares a function-scoped, hoisted variable. Prefer `const` by default, `let` when reassignment is needed, avoid `var`.
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).
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.