Export (0) Print
Expand All
5 out of 6 rated this helpful - Rate this topic

let Statement (JavaScript)

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

Supported in the Internet Explorer 11 standards document mode. Also supported in Store apps (Windows 8.1 and Windows Phone 8.1). See Version Information. Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Not supported in Windows 8.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.