Mutate an Array Declared with const (further understanding questio)

Tell us what’s happening:

My code ran correctly. And i understood that by using the array position and declaring a new value was what allowed me to put the correct values in the solution array but I am wondering if there was another way to go about this that would allow me to see the logical insight behind the challenge. I am in the ES6 section of the course now and still find myself confused at certain points so leveling up my understanding of this material is imperative!

Your code so far


const s = [5, 7, 2];
function editInPlace() {
  "use strict";
  // change code below this line

  s[0] = 2;
  s[1] = 5;
  s[2] = 7;

  // change code above this line
}
editInPlace();

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const

The key idea is that const does not mean not mutable per se, you just cannot re-assign a variable declared this way. So if you have a string, there is no way you can re-assign it, because you can’t simply mutate strings; or numbers. But if you have an object or array, you can change some values that object or array stores, not the variable itself that references that object. I.E. you can’t re-assign myVariable in const myVariable = ..., it will always remain declared and point to something. You can, however, mutate an object {a: 20} that it references to something like {b: 20} like this:

const myVariable = {
  a: 20
};

delete myVariable.a;
myVariable.b = 20; 
// ok, because you don't mutate myVariable,
// only an object it references

const myVariable = "hello";
myVariable = "will not work";
// TypeError because you're trying to re-assign the variable