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 () 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 () below!
Agree with a comment or answer? Like () to up-vote the contribution!
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 ?
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!!!
My only question from this lesson is about logging in changes. When I change my element in my array the exercise instructed me to log in the change. When we change in a array are we suppose to console.log() the change always?
That’s not a requirement, only suggested in the exercise so you can see the change. When we make a change to any element in an array, the change takes place. Once we are certain that our syntax is correct and we’re using a valid approach, we can expect the change.
There are several ways to manipulate an array. Study the Array methods listed on MDN to get an idea of what tools are at our disposal.
I was wondering why when we reassign the variable ‘condiments’ to a new array ([‘Mayo’]) this does not change the output from the first console.log command. Pardon my error in coding parlance, but why when we change the variable ‘condiments’ to a new array does this not have global scope?
I wonder if you could expand on this topic a bit for me. In the previous module we wrote some functions that called on helper functions outwith the function code block that were below that function code block.
If the variable doesn’t exist until it has been “read” (parsed?) top to bottom (or doesnt change unless the change is above the console.log, as in my example above), how can a function use a helper function that is below it in the code?
(P.S the hint number One in Arrays 5/12 says ‘Hans Solo’… unforgivable)
I am just getting my head around why variable require to be assigned above where they can be used (as in my example) but functions (in other situations, not this one) can be called before they are declared.
Step 2 in this exercise is to reassign condiments to be a new array with a single string [‘Mayo’]. I used the let keyword in front of condiments with ‘Mayo’ in the square brackets but got an error saying that condiments was already declared. When i removed the keyword let, the code returned the anticipated answer and I could move onto Step 3. Why isn’t let used to reassign condiments to a new array when it is used initially to create the array?
Because the variable has already been declared. All we need do after that is change the assignment. We do not re-declare variables.
Consider the for loop…
for (let i = 0; i < 10; i++) {
console.log(i + 1)
}
i is not continuously declared in this loop. That directive in the for argument is never re-visited. After that it only gets new values assigned to it until such time as it fails the loop condition.
i++
is equatable to,
i = i + 1
What’s important to see here is the expression on the right. It is a new value. When we assign that, the old value disappears.