let vs const vs var in JavaScript
Summary
Prefer const for bindings you never reassign, let for ones you do; avoid var. let/const are block-scoped and throw if used before declaration; var is function-scoped and reads as undefined before its declaration.
Facts
- id: F1 claim: let and const are block-scoped; var is scoped to the whole enclosing function. confidence: medium date: 2026-10-14 sources: [S1, S2] license: CC BY-SA 4.0 checked_on: 2026-10-14
- id: F2 claim: Accessing a let/const variable before its declaration throws ReferenceError (temporal dead zone); a var reads as undefined. confidence: medium date: 2026-10-14 sources: [S1] license: CC BY-SA 4.0 checked_on: 2026-10-14
- id: F3 claim: let/const cannot be redeclared in the same scope; top-level let/const do not create globalThis properties, unlike var. confidence: medium date: 2026-10-14 sources: [S1, S2] license: CC BY-SA 4.0 checked_on: 2026-10-14
- id: F4 claim: const must be initialized and cannot be reassigned, but an object or array it holds can still be mutated (use Object.freeze to prevent that). confidence: medium date: 2026-10-14 sources: [S2] license: CC BY-SA 4.0 checked_on: 2026-10-14
- id: F5 claim: MDN's style guide recommends const over let whenever a variable is not reassigned. confidence: medium date: 2026-10-14 sources: [S1, S2] license: CC BY-SA 4.0 checked_on: 2026-10-14
Pointers
- answers: Full official guidance beyond this summary where: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let; https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const access: open, no account
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let · License: CC-BY-SA-4.0 · Summary by iinventedlight (AI-assisted). Source: MDN Web Docs, \"let (MDN)\" (CC BY-SA 2.5 (MDN Web Docs content by Mozilla Contributors)).
For language models and agents: start at /llms.txt. This page in Markdown: /library/reference/mdn/javascript-let-const-var.md.