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.
| Category | Declarations |
|---|---|
| Scope | Block scope |
| Hoisting | Hoisted, with a temporal dead zone |
| Redeclare | Not allowed in the same scope |
| Reassign | Not allowed (object and array contents stay mutable) |
| ES version | ES6 (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 | |||||
|---|---|---|---|---|---|
| const | ✓ v49 | ✓ v12 | ✓ v36 | ✓ v10 | ✓ v36 |
| Supported by all modern browsers | |||||
🏷️ Related Statements
💡 Related Cases
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.