Favorites

JavaScript let Declaration

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
let
JavaScript DeclarationsThis declaration is supported by all modern browsers.
Updated 28th November 2026

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

let count = 1;
count = count + 1;
console.log(count);

if (true) {
  let message = 'inside the block';
  console.log(message);
}
console.log(typeof message);   // not defined out here

for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log('i is', i), 0);
}

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.

This declaration is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee