George Emad
2 months ago
Georgecountry asked

What’s the point of using const before an array if we can still change its elements?

Abhay Jajodia
Expert
last month
Abhay Jajodia answered

Hi George,

Good question — it confuses a lot of people at first.

When you use const with an array in JavaScript, you're saying the reference to the array can’t change — not the contents.

So this is allowed:

const fruits = ["Apple", "Banana", "Orange"];
fruits[1] = "Mango";  // ✅ You can update elements

But this is not allowed:

fruits = ["Grapes", "Pineapple"];  // ❌ Error: assignment to constant variable

So const just means you can’t assign a new array to that variable. You can still update, add, or remove elements from the original array.

If you have more questions, I am here to help.

JS
This question was asked as part of the Learn JavaScript Basics course.