JavaScript let Declaration
The let declaration creates a block-scoped variable that can be reassigned later. Unlike var, it is only available inside the block where it is declared.
Description
The let declaration declares a block-scoped variable, optionally giving it a starting value. The variable exists only inside the nearest enclosing block, such as a function body, an if block or a loop, and can be reassigned later.
Unlike var, a let variable can't be used before its declaration: the space between the start of the block and the declaration is the "temporal dead zone", and accessing it there throws a ReferenceError. Declaring the same name twice in one scope is a SyntaxError, and let variables at the top level don't become properties of window.
Use const by default for values that won't be reassigned, and let for values that will, such as counters. In loops, let creates a new binding for each iteration, which fixes the classic problem of callbacks created in a var loop all seeing the final value.
Syntax
let name;
let name = value;
let name1 = value1, name2 = value2;Example
Browser Support
The following information will show you the current browser support for the let declaration. Hover over a browser icon to see the version that first introduced support for this declaration.
Desktop





Tablets & Mobile





