let Statement

Last updated: 2026-09-09

let Statement

let declares a block-scoped variable: it only exists inside the nearest pair of curly braces, cannot be accessed outside them, and cannot be redeclared in the same scope. Introduced in ES6, it is the modern replacement for var.

CategoryDeclarations
ScopeBlock scope
HoistingHoisted, but stays in the temporal dead zone until the declaration runs
RedeclareNot allowed in the same scope
ReassignAllowed
ES versionES6 (2015)

📝 Syntax

let name = value;

⚙️ Parameters

变量名An identifier: starts with a letter, underscore or dollar sign, is case-sensitive, and cannot be a reserved word.
初始值Optional. When omitted the variable holds undefined and can be assigned later.

Returns:Returns nothing — let is a statement, not an expression.

Mutates the original:No (returns a new value)

▶ Example

Edit the code, press Run, and see the result in the output panel:

Output:

2
visible inside the block
Error: ReferenceError
💡 Tip A let counter in a loop creates a fresh binding per iteration, so callbacks such as setTimeout capture the value of that iteration. With var they would all see the final value.
⚠️ Warning Redeclaring the same name with let in one scope throws a SyntaxError instead of silently overwriting, which helps you catch naming conflicts early.

🌐 Browser support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
let v49 v12 v44 v10 v36
Supported by all modern browsers
More case studies coming soon — check back later.

📚 Related Tutorials

❓ FAQ

QWhat is the difference between let and var?
AThree things: scope (let is block-scoped, var is function-scoped and may leak onto the global object), redeclaration (let forbids it, var allows it), and hoisting (let keeps the binding in the temporal dead zone and throws, var yields undefined).
QWhy does using a let variable before its declaration throw an error?
AThe span between entering a scope and running the let declaration is called the temporal dead zone (TDZ). The binding exists but is uninitialized, so touching it throws a ReferenceError. This is intentional: it prevents the silent undefined bugs that var allows.
QWhy does let behave differently inside loops?
AWith let, each iteration gets its own copy of the loop variable (carrying over the previous value), so every closure captures its own iteration. With var there is a single shared binding, so callbacks later all observe the last value.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏