let
Declares a block-scoped, reassignable variable.
Syntax
let name;
let name = value;
let name1 = value1, name2 = value2;
Returns
undefined — `let` is a statement, not an expression — it does not produce a
value.
Throws
SyntaxError— The same name is declared twice in the same block.ReferenceError— A `let` binding is accessed before its declaration runs (this is the **temporal dead zone**).
Examples
let count = 0;
count = count + 1;
console.log(count);
Output
1
// Multiple declarations on one line
let x = 1, y = 2, z = 3;
console.log(x + y + z);
Output
6
// Block scope
{
let inner = "scoped";
console.log(inner); // "scoped"
}
// console.log(inner); // ReferenceError
Output
scoped
// Temporal dead zone
// console.log(early); // ReferenceError
let early = "now I exist";
console.log(early);
Output
now I exist
Notes
- Prefer `const` over `let`. Use `let` only when you genuinely need
to reassign.
- `let` and `const` are block-scoped (`var` is function-scoped).
- Redeclaring a `let` in the same block is a `SyntaxError`. You
can shadow it in a nested block, though.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 49 |
| firefox | 44 |
| safari | 11 |
| edge | 14 |
| node | 6.0 |