Skip to content

Latest commit

 

History

History
73 lines (61 loc) · 1.88 KB

File metadata and controls

73 lines (61 loc) · 1.88 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
const Statement (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
const_JavaScriptKeyword
JavaScript
TypeScript
DHTML
declaring variables, const statement
const statement
3ad0840f-437f-4163-9571-86ecc5ddb987
7
mikejo5000
mikejo
ghogen

const Statement (JavaScript)

Declares a block-scoped variable with a constant value.

Syntax

const constant1 = value1  

Parameters

constant1
The name of the variable being declared.

value1
The initial value assigned to the variable.

Remarks

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.

Example

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

Requirements

[!INCLUDEjsv11]

See Also

let Statement
new Operator
Array Object
Variables