[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Errors/Invalid_const_assignment [Back]  [Original]

TypeError: invalid assignment to const "x"( const "x") - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

TypeError: invalid assignment to const "x"( const "x")

TypeError:   const "x" (Firefox)
TypeError:   . (Chrome)
TypeError:  const (Edge)
TypeError:   const 'x' (IE)

In this article

TypeError

?

- , . . JavaScript, const.

Assigning a value to the same constant name in the same block-scope will throw.

js
const COLUMNS = 80;

// ...

COLUMNS = 120; // TypeError: invalid assignment to const `COLUMNS'

, . , .

, . .

js
const COLUMNS = 80;
const WIDE_COLUMNS = 120;

const, let var?

const, . , let var.

js
let columns = 80;

// ...

let columns = 120;

, . , ?

js
const COLUMNS = 80;

function setupBigScreenEnvironment() {
  const COLUMNS = 120;
}

const

const . , , , , . , , , . , , :

js
const obj = { foo: "bar" };
obj = { foo: "baz" }; // TypeError: invalid assignment to const `obj'

:

js
obj.foo = "baz";
obj; // Object { foo: "baz" }


Web Proxy Viewer  |  New URL  |  Original Page