ES6 - Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements

Task: Use destructuring assignment with the rest parameter to perform an effective Array.prototype.slice() so that arr is a sub-array of the original array source with the first two elements omitted.

The solution is listed below but makes zero sense to me. How can that possibly be the solution when that line of code doesnt even reference the “source” variable?

const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
  // Only change code below this line
  const [a, b, ...arr] = list; // Change this line
  // Only change code above this line
  return arr;
}
const arr = removeFirstTwo(source);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0

Challenge: ES6 - Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements

Link to the challenge:

This line passes source as an argument to the removeFirstTwo function. The function parameter list is a reference to the argument that gets passed to removeFirstTwo.

This means they are the same array.

Hi Qlander!

The line of code does refer to the “source” variable. If you check at the very bottom, there is a declaration of variable arr and the value of variable arr is the invocation of removeFirstTwo(source) function.

This means that removeFirstTwo function is taking “source” variable as its argument and therefore the “source” variable will be affected by removeFirstTwo function.

If I can explain it a little, “list” inside of removeFirstTwo(list), is a parameter —> an identifier inside a function. while “source” inside of removeFirstTwo(source), is an argument —> the value of the identifier.

It is kind of similar with normal variable declaration like: let name = ‘Ronaldo’. name is the identifier, ‘Ronaldo’ is the value.

Hope this helps.

It seems like to me that the function removeFirstTwo(list) should really be: removeFirstTwo().

But it sounds like you’re saying that the “list” argument inside the () can be replaced with any argument? Is that correct?

list is a parameter (a placeholder variable for use inside the function).

You could have named it anything. The important thing to remember is that the argument that gets passed to the function (when it is called) becomes the parameter’s value.

If you are struggling with this syntax, you should probably review this challenge in the Basic JavaScript section before proceeding with the current challenge.

As explained by RandellDawson, “list” in this case is acting as a placeholder, which means a place that will hold value. When you first declare function removeFirstTwo(list) , there isn’t any value being assigned to "list.

However, when you invoke/call the function using const arr = removeFirstTwo(source), you are now giving a value to the list and the value is the “source” variable;

This is currently my 2nd time going through the JAVA section. I’ve been struggling with convincing my brain that these lessons are to be retained and not purged. It appears as though I will have to settle for brute force tactics.

Thanks for your help.

Note - Java and Javascript are different things