| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
let Statement (JavaScript) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
|
|
c7e4f8a9-8f54-47b6-aed2-956959c1ecfd |
7 |
mikejo5000 |
mikejo |
ghogen |
Declares a block-scoped variable.
let variable1 = value1
variable1
The name of the variable being declared.
value1
The initial value assigned to the variable.
Use the let statement to declare a variable, the scope of which is restricted to the block in which it is declared. You can assign values to the variables when you declare them or later in your script.
A variable declared using let cannot be used before its declaration or an error will result.
If you do not initialize your variable in the let statement, it is automatically assigned the [!INCLUDEjavascript] value undefined.
The following example illustrates the use of the let statement.
var l = 10;
{
let l = 2;
// At this point, l = 2.
}
// At this point, l = 10.
// Additional ways to declare a variable using let.
let index;
let name = "Thomas Jefferson";
let answer = 42, counter, numpages = 10;
let myarray = new Array();
[!INCLUDEjsv11]