Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The const declaration declares block-scoped local variables. The value of a constant can't be changed through reassignment using the assignment operator, but if a constant is an object, its properties can be added, updated, or removed.
The name of the variable to declare. Each must be a legal JavaScript identifier or a destructuring binding pattern.
valueNInitial value of the variable. It can be any legal expression.
The const declaration is very similar to let:
const declarations are scoped to blocks as well as functions.
const declarations can only be accessed after the place of declaration is reached (see temporal dead zone). For this reason, const declarations are commonly regarded as non-hoisted.
const declarations do not create properties on globalThis when declared at the top level of a script.
const declarations cannot be redeclared by any other declaration in the same scope.
const begins declarations, not statements. That means you cannot use a lone const declaration as the body of a block (which makes sense, since there's no way to access the variable).
An initializer for a constant is required. You must specify its value in the same declaration. (This makes sense, given that it can't be changed later.)
The const declaration creates an immutable reference to a value. It does not mean the value it holds is immutable — just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its properties) can be altered. You should understand const declarations as "create a variable whose identity remains constant", not "whose value remains constant" — or, "create immutable bindings", not "immutable values".
Many style guides (including MDN's) recommend using const over let whenever a variable is not reassigned in its scope. This makes the intent clear that a variable's type (or value, in the case of a primitive) can never change. Others may prefer let for non-primitives that are mutated.
The list that follows the const keyword is called a binding list and is separated by commas, where the commas are not comma operators and the = signs are not assignment operators. Initializers of later variables can refer to earlier variables in the list.
Constants can be declared with uppercase or lowercase, but a common convention is to use all-uppercase letters, especially for primitives because they are truly immutable.
It's important to note the nature of block scoping.
const also works on objects and arrays. Attempting to overwrite the object throws an error "Assignment to constant variable".
However, object keys are not protected, so the following statement is executed without problem.
You would need to use Object.freeze() to make an object immutable.
The same applies to arrays. Assigning a new array to the variable throws an error "Assignment to constant variable".
Still, it's possible to push items into the array and thus mutate it.
The left-hand side of each = can also be a binding pattern. This allows creating multiple variables at once.
For more information, see Destructuring.
| ECMAScript® 2027 Language Specification # sec-let-and-const-declarations |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.