const Statement

Last updated: 2026-09-09

const Statement

const declares a block-scoped constant: it must be initialized immediately and the name cannot later be bound to another value. What is locked is the binding, not the value — properties of a const object and items of a const array remain mutable.

CategoryDeclarations
ScopeBlock scope
HoistingHoisted, with a temporal dead zone
RedeclareNot allowed in the same scope
ReassignNot allowed (object and array contents stay mutable)
ES versionES6 (2015)

📝 Syntax

const NAME = value;

⚙️ Parameters

常量名By convention UPPER_SNAKE_CASE such as MAX_SIZE; the language does not enforce it.
Required — a const must be initialized in the same statement.

Returns:Returns nothing — const is a statement.

Mutates the original:No (returns a new value)

▶ Example

Edit the code, press Run, and see the result in the output panel:

Output:

3.14
Reassignment error: TypeError
Li Si
⚠️ Warning const prevents rebinding the name, not mutating the value. Use Object.freeze(obj) for a shallow freeze.
💡 Tip Default to const and switch to let only when you really need to reassign; readers can then see at a glance which bindings never change.

🌐 Browser support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
const v49 v12 v36 v10 v36
Supported by all modern browsers
More case studies coming soon — check back later.

📚 Related Tutorials

❓ FAQ

QWhy can I still change properties of a const object?
Aconst locks the binding between the name and the value — the name always points at that same object. The contents of the object are not part of the contract, so adding or editing properties is legal. Only rebinding (user = {}) throws a TypeError.
QCan I declare a const without a value?
ANo. The syntax forbids it: const x; throws SyntaxError: Missing initializer in const declaration. This is one of the clearest differences from let.
QWhen should I use const and when let?
AReach for const whenever the name is never rebound: constants, config, function expressions, imported modules, DOM references. Use let for loop counters and values you accumulate. var is rarely needed in new code.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏