| 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 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
const Statement (JavaScript) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
|
|
3ad0840f-437f-4163-9571-86ecc5ddb987 |
7 |
mikejo5000 |
mikejo |
ghogen |
Declares a block-scoped variable with a constant value.
const constant1 = value1
constant1
The name of the variable being declared.
value1
The initial value assigned to the variable.
Use the const statement to declare a variable with a constant value, the scope of which is restricted to the block in which it is declared. The value of the variable cannot be changed.
A variable declared using const must be initialized when it is declared.
The following example illustrates the use of the const statement.
var c = 10;
{
const c = 2;
// At this point, c = 2.
}
// At this point, c = 10.
// Additional ways to declare a variable using const.
const name = "Thomas Jefferson";
const answer = 42, numpages = 10;
const myarray = new Array();
[!INCLUDEjsv11]