Skip to content

const

In JavaScript, the const keyword declares a block-scoped binding that can’t be reassigned after its declaration. Like let, a const binding exists only inside the nearest enclosing block, loop, or function, which sets it apart from var. Every const declaration needs an initializer, so const total; is a SyntaxError.

The keyword fixes the binding, not the value. Assigning to a const binding throws a TypeError in both strict and sloppy mode, but an object or array stored in it can still change. Locking the value itself takes a call such as Object.freeze(), which freezes only the top level.

A const binding sits in the temporal dead zone until its declaration runs, and it can’t be redeclared in the same scope. ECMAScript has reserved the word since its first edition, and const declarations became standard in ES2015.

JavaScript const Keyword Syntax

A const declaration has the following form:

Language: JavaScript Syntax
const <name> = <value>[, <name2> = <value2>, ...];

The name can also be a destructuring pattern.

JavaScript const Keyword Examples

A const binding can’t be reassigned, but the array it points to can still change:

Language: JavaScript
> const scores = [90, 85];
undefined

> scores.push(70);
3
> scores
[ 90, 85, 70 ]

> scores = [];
Uncaught TypeError: Assignment to constant variable.

Calling .push() changes the array that scores points to, so it works. Assigning a new array tries to change the binding itself, so it throws.

A const binding can head a for...of loop, because each iteration gets a fresh binding:

Language: JavaScript
> for (const city of ["Lima", "Oslo"]) {
…   console.log(city.toUpperCase());
… }
LIMA
OSLO
undefined

A classic for loop with const i = 0 throws a TypeError at the first i++, which reassigns the binding.

JavaScript const Keyword Use Cases

  • Declaring bindings that shouldn’t be reassigned
  • Holding objects, arrays, and functions whose contents may change
  • Declaring loop variables in for...of and for...in loops
  • Unpacking values with destructuring into fixed bindings

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 4, 2026