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

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

MDN Web Docs

View in English Always switch to English

TypeError: invalid assignment to const "x"

TypeError: invalid assignment to const "x" (Firefox)
TypeError: Assignment to constant variable. (Chrome)
TypeError: Redeclaration of const 'x' (IE/Edge)

TypeError

JavaScript const

js
const COLUMNS = 80;

// ...

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

js
const COLUMNS = 80;
const WIDE_COLUMNS = 120;

const, let or 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