FAQ: Arrays - Arrays with let and const


#1

This community-built FAQ covers the “Arrays with let and const” exercise from the lesson “Arrays”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Arrays with let and const

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Hi,
I just completed the " Arrays with let and const" section and I must say I don’t get the explanation that says : " However, if a const variable contains an array, you can mutate elements in the array but not re-assign an new value!"
–> What we were asked to do in the exercice consisted (to me) to reassign a value to an element stored in a const variable… Which is way I don’t get the subtelty between “mutating” an element and “re-assigning it a new value”. Can someone help me on this ? :slight_smile:


#3

lets do analogy, lets say you build a house (which represents a an array declared with constant):

const myHouse = ['living_room', 'bath_room', 'kitchen'];

you can perfectly change things in the house, add a dishwasher for example:

const myHouse =  ['living_room', 'bath_room', 'kitchen'];
myHouse.push('dishwasher');

however, you can’t just replace the house:

const myHouse = ['living_room', 'bath_room', 'kitchen'];
myHouse = ['new_house']; // error

so that is the difference between mutation (manipulating the array itself), and re-assigning the variable.


#4

Hello, i was working with let and const but i deleted the elements in the condiments array. I restored my worksheet but it didn’t restore to the original array but the one i deleted. Kindly help with the elements in the condiment array!!!


#5

Here is what comes up in the lesson, for me. Is this what you are looking for?

let condiments = ['Ketchup', 'Mustard', 'Soy Sauce', 'Sriracha'];