What is const in JavaScript
Explore what const means in JavaScript, how bindings work, differences from let and var, and practical use cases and pitfalls for developers learning modern ES6 syntax.

Const is a keyword that declares a block scoped binding whose value cannot be reassigned. The binding is read-only, but the value can be mutated if it is an object or array.
How const Works in JavaScript
Const declares a binding that is block scoped and cannot be reassigned. When you write const x = 10, you create a binding named x that exists only within the current block. Any attempt to reassign x, such as x = 20, results in a TypeError. Importantly, const does not make the value immutable. If the value is an object, its properties can still be changed, and if it is an array you can push or pop elements. Another critical detail is the Temporal Dead Zone: the name x exists in the scope but cannot be read before the initialization line, otherwise a ReferenceError is thrown. This behavior helps catch mistakes early. In practice, const is ideal for bindings that should not be reassigned, like module imports, configuration objects, or constants used to guard logic. However, you should still be careful with composite values because mutating the contents of an object or array does not violate the const constraint. The JavaScripting team emphasizes using const to convey intent and reduce accidental reassignment.
const vs let and var: A quick comparison
In modern JavaScript, const and let are both block scoped, while var is function scoped. The main practical difference between const and let is reassignment: you can reassign a let binding later but not a const binding. However, both cannot be redeclared in the same scope. Another nuance is that const requires initialization at declaration; let can be declared without initialization. Because of these rules, many developers adopt a simple guideline: prefer const by default and use let only when you know a value will change. This reduces accidental reassignments and clarifies intent. Understanding the semantics of these keywords helps you write more predictable code. In real world code, you might declare a collection with const and then modify its contents as your program runs, which is a common pattern in state management, data processing, and functional style code.
When to use const in real world projects
Most modern JavaScript codebases adopt a const-first approach. If a binding should never be reassigned after its initial set, declare it with const. This includes imports, configuration objects, factory results that you do not intend to rebind, and references to DOM nodes captured at initialization. For values that will change over time, such as counters or temporary holders, use let. This discipline reduces bugs related to accidental reassignment and makes the code easier to reason about during code reviews and debugging sessions. The JavaScripting team recommends pairing const with immutable data patterns when feasible and using pure functions to minimize mutable state in complex apps.
Common pitfalls and misconceptions
A frequent mistake is assuming that const makes the value stored immutable. The binding cannot be reassigned, but if the value is an object or array, its internal state can change. Another pitfall is forgetting that const declarations must be initialized at the moment of declaration; leaving the binding uninitialized will throw an error. People also forget that const is block scoped, so you can have a const x inside a block with a different binding than an outer x. Always remember that redeclaring a const in the same scope is a syntax error. Finally, treat const as a tool for design clarity—use it to express intent and prevent accidental rebinding, not as a guarantee of immutability.
Practical examples primitives vs objects
Consider a primitive value
const count = 5;
// count = 6; // TypeError: Assignment to constant variableNow consider an object
const user = { name: 'Ava', age: 30 };
user.age = 31; // allowed
user = { name: 'Kai' }; // TypeError: Assignment to constant variableThe first example shows binding immutability, the second shows mutability of the object contents. This distinction is fundamental when designing state containers or data models in JavaScript applications.
Best practices for const declarations
Always prefer const when you do not need to rebind variables. Initialize at declaration to avoid TDZ related errors. Group related const declarations together to improve readability, and use descriptive names to convey intent. When working with arrays or objects, consider freezing the outer object to express immutability, or adopt functional programming patterns that minimize mutation. Finally, enable lint rules such as no constant reassignment and prefer-const to reinforce these habits across the codebase.
Tooling and compatibility considerations
Const is a core feature of ES6 and is supported by all modern browsers and Node.js versions. If you must support very old environments, use a transpiler like Babel as part of your build pipeline. ESLint rules can help enforce const usage and prevent reassignments in large projects. In team settings, adopting a const heavy approach often reduces bugs and clarifies intent when reviewing pull requests. JavaScript tooling and IDEs now provide real time feedback about TDZ and reassignment, making const usage safer and more intuitive across large codebases.
Getting started with const in your projects
Start by scanning existing code for variables that never change after initialization and convert them to const. Move through small, incremental changes to avoid introducing bugs. Use unit tests to verify behavior around mutated objects and arrays. Over time, a const driven style helps create predictable, easy to reason about code, which is especially beneficial for beginners learning JavaScript and professionals refining their practice.
Questions & Answers
What is the difference between const and let?
Const and let are both block scoped, but const bindings cannot be reassigned after initialization. Let bindings can be reassigned later. Both cannot be redeclared in the same scope.
Const bindings cannot be reassigned; let bindings can be reassigned. Both are block scoped and cannot be redeclared in the same scope.
Can I reassign a const variable?
No. A const binding cannot be reassigned after its initial assignment. Attempting to do so results in a TypeError.
No. You cannot reassign a const binding after it is initialized.
Does const make objects immutable?
No. The binding itself is immutable, but the object’s properties can be changed. Arrays and objects assigned to const can be mutated.
No. Const makes the binding immutable, but the value can still be mutated if it is an object or array.
When do I need to initialize a const?
You must initialize a const at the time of declaration. Leaving it uninitialized results in a syntax error.
Const must be initialized at declaration; otherwise you’ll get a syntax error.
Is const supported in all environments?
Const is supported by modern environments. For very old browsers, use a transpiler as part of your build process.
Most environments support it, but older browsers may require transpilation.
What happens if I declare a const inside a block and reuse the name outside?
Const is block scoped. A const inside a block creates a new binding that does not affect an outer binding with the same name.
Const is block scoped; inner declarations do not affect outer ones.
What to Remember
- Declare bindings with const by default.
- Initialize a const at the moment of declaration.
- Mutate object contents, not the binding itself.
- Prefer const to reduce accidental reassignments.
- Avoid redeclaring const in the same scope.