CKTIS / JavaScript
let — block-scoped variable declaration
let declares a block-scoped variable that can be reassigned. Learn initialization, shadowing, and the temporal dead zone, plus the differences from var and const.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
let name;
let name = expression;
let first = expression, second = expression;let declares a lexically scoped variable: a declaration inside a { ... } block belongs to that block rather than the entire function as with var. A variable declared with let can be reassigned; const prohibits reassignment of the binding.
The declaration let name; initializes the variable to undefined when execution reaches it. The declaration let name = expression; uses the expression's value. The binding exists earlier but remains uninitialized: the period from entry into its scope until initialization is the temporal dead zone (TDZ). Reading it during this period, including through typeof name, throws ReferenceError.
Redeclaring the same name with let in the same scope causes a SyntaxError. However, a separate nested block can declare its own variable with that name and shadow the outer one. The TDZ then applies to the inner binding from the beginning of its scope; an earlier read does not fall back to the outer variable.
In the example, the inner count changes from 10 to 12, independently of the outer count. After leaving the block, the outer variable changes from 1 to 2.
Examples
let count = 1;
{
let count = 10;
count += 2;
console.log(count);
}
count += 1;
console.log(count);Result
12 2
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.