| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Errors/Invalid_const_assignment | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
TypeError: const "x" (Firefox) TypeError: . (Chrome) TypeError: const (Edge) TypeError: const 'x' (IE)
TypeError
- , . . JavaScript, const.
Assigning a value to the same constant name in the same block-scope will throw.
const COLUMNS = 80;
// ...
COLUMNS = 120; // TypeError: invalid assignment to const `COLUMNS'
, . , .
, . .
const COLUMNS = 80;
const WIDE_COLUMNS = 120;
const, let var?const, . , let var.
let columns = 80;
// ...
let columns = 120;
, . , ?
const COLUMNS = 80;
function setupBigScreenEnvironment() {
const COLUMNS = 120;
}
const const . , , , , . , , , . , , :
const obj = { foo: "bar" };
obj = { foo: "baz" }; // TypeError: invalid assignment to const `obj'
:
obj.foo = "baz";
obj; // Object { foo: "baz" }
This page was last modified on 7 . 2023 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |