Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

const Statement (JavaScript)

Declares a block-scoped variable with a constant value.

const constant1 = value1


The name of the variable being declared.


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

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.

© 2015 Microsoft