const varname1 = value1 [, varname2 = value2 [, varname3 = value3 [, ... [, varnameN = valueN]]]];
Creates a constant that can be global or local to the function in which it is declared. Constants follow the same scope rules as variables.
The value of a constant cannot change through re-assignment, and a constant cannot be re-declared. Because of this, although it is possible to declare a constant without initializing it, it would be useless to do so.
A constant cannot share its name with a function or a variable in the same scope.
The current implementation of
const is a Mozilla-specific extension and is not part of ECMAScript 5. It is supported in Firefox & Chrome (V8). As of Safari 5.1.7 and Opera 12.00, if you define a variable with
const in these browsers, you can still change its value later. It is not supported in Internet Explorer 6-9, or in the preview of Internet Explorer 10. The
const keyword currently declares the constant in the function scope (like variables declared with
FIrefox, as of version 13, will throw a TypeError if you try to redefine a constant. None of the major browsers will produce any notices or errors if you later try to assign another value to a constant. In all these browsers, the return value of such an operation will be that of the new value assigned. Only in Firefox and Chrome (as of version 20) will the reassignment be unsuccessful.
const is going to be defined by ECMAScript 6, but with different semantics. Similar to variables declared with the
let statement, constants declared with
const will be block-scoped.
a is 7."
const a = 7; console.log("a is " + a + ".");