Skip to content

let

In JavaScript, the let keyword declares a block-scoped variable that can be reassigned later. A let binding exists only inside the nearest enclosing block, loop, or function, which sets it apart from var. For bindings that never change, const is the usual choice.

The binding is created when its scope starts, but reading it before the declaration runs throws a ReferenceError. That stretch of code is the temporal dead zone, which is why let declarations behave differently under hoisting than var declarations do. Declaring the same name twice with let in one scope is a SyntaxError. At the top level of a script, let doesn’t create a property on the global object.

let was added in ES2015. It’s one of the strict-mode reserved words, so sloppy-mode code can still use let as an identifier, though not as the name in a let, const, or class declaration.

JavaScript let Keyword Syntax

A let declaration has the following form:

Language: JavaScript Syntax
let <name> [= <value>][, <name2> [= <value2>], ...];

The name can also be a destructuring pattern, and the initializer defaults to undefined.

JavaScript let Keyword Examples

A let binding can be reassigned, and a let inside a block creates a separate binding:

Language: JavaScript
> let count = 1;
undefined
> count += 1;
2

> {
…   let count = 100;
… }
undefined
> count
2

The inner count is a separate binding that lives only inside the braces, so the outer count keeps its value.

Reading a let binding before its declaration throws an error:

Language: JavaScript
> {
…   total;
…   let total = 0;
… }
Uncaught ReferenceError: Cannot access 'total' before initialization

JavaScript let Keyword Use Cases

  • Declaring counters and accumulators that change over time
  • Creating a fresh binding for each iteration of a for loop
  • Limiting a variable to the block where it’s needed
  • Declaring a variable whose value is assigned later in a branch

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 6, 2026