| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/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 7.
const . .
const number = 42;
try {
number = 99;
} catch (err) {
console.log(err);
// Expected output: TypeError: invalid assignment to const 'number'
// (Note: the exact output may be browser-dependent)
}
console.log(number);
// Expected output: 42
const name1 = value1 [, name2 = value2 [, ... [, nameN = valueN]]];
. (initializer) . ( ).
let (block-scope). .
let " " , const .
.
. .
// : ,
// .
// MY_FAV 7
const MY_FAV = 7;
//
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 )
let 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);
// const
const FOO;
// const
const MY_OBJECT = { key: "value" };
//
MY_OBJECT = { OTHER_KEY: "value" };
// .
//
MY_OBJECT.key = "otherValue"; // Object.freeze()
//
const MY_ARRAY = [];
//
MY_ARRAY.push("A"); // ["A"]
//
MY_ARRAY = ["B"];
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-let-and-const-declarations |
This page was last modified on 2025 6 27 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 |