0d: 00h: 00m: 00s

🎁 Get 3 extra months of learning — completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

🎁 Get 3 extra months of learning completely FREE

Become a PRO
George Emad
last month
Georgecountry asked

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

Abhay Jajodia
Expert
2 days ago
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.