JavaScript JavaScript Arrays Multidimensional Arrays Improve the Quiz – One Solution

Mason Aviles
Mason Aviles
2,105 Points

let or const for lines 10-12

on line 12, you use let for correct answers, I'm assuming because the value changes after each correct answer. but for lines 10 and 11, you use const even though they change too.

Do you use const because it's the same array but just being added to? vs, the let it changes the value completely?

1 Answer

Hi Marian!

Affirmative Earthling!?! LOL J/K, of course!?!

BTW, if you haven't seen Resident Alien on the Sci-Fi channel it's hilarious! (SOOOOOOO funny!). You can watch it On Demand or on the website (as well as on the Sci-Fi channel).

But, yes, you are correct.

An array declared as a const has all the behaviors/qualities of an array, but you can't change its type (to an int or string or anything else - it can only be the original declared array).

const cars = ["Saab", "Volvo", "BMW"];
cars.push("Fiat"); // No error
cars = 2; // Uncaught TypeError: Assignment to constant variable.

With let, you can, but with limited (and protective) scope.

With var, it's anything goes, which is why they came up with let and const, for some variable usage safeguards.

More info:

I hope that helps.

Stay safe and happy coding!