Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

const — declaring an immutable binding

The const keyword declares a block-scoped name that cannot be assigned another value after initialization. It does not make an object or array accessed through that name immutable.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

const name = expression;

const creates an immutable binding between a name and a value. It is block-scoped: a declaration inside { ... } is not accessible outside that block. Unlike let, it does not allow reassignment; attempting reassignment throws TypeError, even outside strict mode.

An ordinary declaration requires an initializer: const name = expression;. Writing only const name; is a syntax error. In for...of and for...in headers, the value comes from iteration, so no initializer is written. Destructuring is also supported, for example const { count } = settings;.

The binding exists from the beginning of its scope but remains uninitialized until its declaration executes. This period is called the temporal dead zone (TDZ); reading the name during this time, including through typeof, throws ReferenceError. Redeclaring the same name in the same lexical scope is a syntax error; a separate nested block may shadow it.

const does not freeze object values. In the example, changing settings.count is allowed, but assigning a new object to settings throws TypeError. Choose let when the same name needs to refer to a different value later.

Examples

{
  const settings = { count: 1 };
  settings.count += 1;
  console.log(settings.count);

  try {
    settings = { count: 3 };
  } catch (error) {
    console.log(error.name);
  }
}

Result

2
TypeError

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources