| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/const | [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.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..
, . (const) , , let.
const name1 = value1 [, name2 = value2 [, ... [, nameN = valueN]]];
, , , . window, var-. ; ( , ).
const ( ), . , , , . , , .
, let const.
.
, const. JavaScript- .
// : ,
// .
// .
// MY_FAV 7
const MY_FAV = 7;
// - Uncaught TypeError: Assignment to constant variable.
MY_FAV = 20;
// 7
console.log("my favorite number is: " + MY_FAV);
// , - Uncaught SyntaxError: Identifier 'MY_FAV' has already been declared
const MY_FAV = 20;
// MY_FAV ,
//
var MY_FAV = 20;
//
let MY_FAV = 20;
//
if (MY_FAV === 7) {
// . MY_FAV .
// ( let , const)
const MY_FAV = 20;
// MY_FAV 20
console.log("my favorite number is " + MY_FAV);
//
var MY_FAV = 20;
}
// MY_FAV 7
console.log("my favorite number is " + MY_FAV);
// , - Uncaught SyntaxError: Missing initializer in const declaration
const FOO;
// const
const MY_OBJECT = { key: "value" };
// - Uncaught TypeError: Assignment to constant variable.
MY_OBJECT = { OTHER_KEY: "value" };
// , ()
MY_OBJECT.key = "otherValue"; // Object.freeze() ,
//
const MY_ARRAY = [];
// ,
MY_ARRAY.push("A"); // ["A"]
// . - Uncaught TypeError: Assignment to constant variable
MY_ARRAY = ["B"];
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-let-and-const-declarations |
This page was last modified on 1 . 2025 . 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 |