Can You Change a const Value in JavaScript?
Learn whether you can change a const value in JavaScript. Understand primitive vs reference types, objects, arrays, and why const doesn't always mean immutable.
Muhammad Ali
Full Stack Developer
TechCamp Pro
Learn whether you can change a const value in JavaScript. Understand primitive vs reference types, objects, arrays, and why const doesn't always mean immutable.
Muhammad Ali
Full Stack Developer

No. It only prevents reassignment. Object properties can still change.
Occasional notes on code, craft, and things I break along the way. No spam — unsubscribe anytime.
Written by
Muhammad Ali
Full Stack Developer
Learn whether you can change a const value in JavaScript. Understand primitive vs reference types, objects, arrays, and why const doesn't always mean immutable.
One of the most common JavaScript interview questions is:
Can we change a
constvalue?
Most developers immediately answer:
No.
But that's only partially correct.
The real answer is:
It depends on what the
constis storing.
Let's understand why.
const Actually Mean?Many developers think const means the value can never change.
That's not true.
const simply means the variable cannot be reassigned to a new value.
Whether the value itself can change depends on its type.
Primitive values cannot be changed.
const age = 24;
age = 25;
Output:
TypeError: Assignment to constant variable.
Because you're trying to assign a completely new value.
The same applies to:
Now let's look at an object.
const user = {
name: "TechCamp Pro",
age: 24,
};
user.age = 25;
console.log(user);
Output
{
name: "TechCamp Pro",
age: 25
}
Did JavaScript allow this?
Yes.
Because you didn't replace the object.
You only changed one of its properties.
The same rule applies to arrays.
const fruits = ["Apple", "Mango"];
fruits.push("Orange");
console.log(fruits);
Output
["Apple", "Mango", "Orange"]
This works perfectly.
Because the array reference never changed.
Replacing the entire object.
const user = {
name: "Ali",
};
user = {
name: "Ahmed",
};
Output
TypeError: Assignment to constant variable.
JavaScript prevents reassignment.
Objects and arrays are reference types.
When you write:
const user = {
name: "Ali",
};
The variable stores a reference (memory address) to the object.
user
│
▼
Memory
{
name: "Ali"
}
Changing a property modifies the existing object in memory.
user.name = "Ahmed";
The reference stays the same.
But this creates a new object:
user = {
name: "Ahmed",
};
Now the reference changes, which const does not allow.
Use Object.freeze().
const user = Object.freeze({
name: "Ali",
});
user.name = "Ahmed";
console.log(user.name);
Output
Ali
The object cannot be modified.
Note:
Object.freeze()is shallow. Nested objects can still be changed unless they are frozen as well.
If an interviewer asks:
Can we change a
constvalue?
A strong answer is:
Primitive values cannot be reassigned. Objects and arrays declared with
constcan have their contents modified becauseconstprotects the reference, not the object itself.
const prevents reassignment.Object.freeze() for immutability.The biggest misconception about const is that it makes values immutable.
In reality, const only prevents changing the variable's reference.
If the variable holds an object or array, you can still modify its contents—as long as you don't assign a completely new object or array.
Understanding this difference is essential for writing better JavaScript and performing well in technical interviews.