Skip to content

Latest commit

 

History

History
76 lines (63 loc) · 2.08 KB

File metadata and controls

76 lines (63 loc) · 2.08 KB
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
devlang-javascript
language-reference
let_JavaScriptKeyword
JavaScript
TypeScript
DHTML
let statement
declaring variables, let statement
c7e4f8a9-8f54-47b6-aed2-956959c1ecfd
7
mikejo5000
mikejo
ghogen

let Statement (JavaScript)

Declares a block-scoped variable.

Syntax

let variable1 = value1  

Parameters

variable1
The name of the variable being declared.

value1
The initial value assigned to the variable.

Remarks

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.

Example

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();  
  

Requirements

[!INCLUDEjsv11]

See Also

const Statement
new Operator
Array Object
Variables