JavaScript const Declaration
The const declaration creates a block-scoped variable that must be given a value and can't be reassigned. Objects it holds can still be changed.
Description
The const declaration creates a block-scoped variable that can't be reassigned. It must be initialized in the declaration, and like let it can't be used before that line (the temporal dead zone).
const makes the binding constant, not the value. An object or array stored in a const can still have its contents changed; use Object.freeze() to prevent that. Many style guides use const by default and let only for variables that will be reassigned, which makes code easier to follow.
Declaring something with const tells anyone reading the code that the name will always refer to the same value, which makes code easier to reason about. It works with destructuring, const { name, age } = user, and in for...of and for...in loops, where each iteration gets a fresh binding. It can't be used for the counter in a classic for loop, because the counter is reassigned on every pass.
Syntax
const name = value;
const name1 = value1, name2 = value2;Example
Browser Support
The following information will show you the current browser support for the const declaration. Hover over a browser icon to see the version that first introduced support for this declaration.
Desktop





Tablets & Mobile





