Use Destructuring Assignment with the Rest Operator to Reassign Array Elements (LESSON)

Tell us what’s happening:

This lesson name is confusing to me because I believe we are using the spead operator here and not the rest operator. When we are passing it as a parameter into a function we know we are using the rest operator. I was confused and found out about rest parameters. Based on the definition they are not the same thing. Are they the same thing though? Here’s the MDN definition => The rest parameter syntax allows us to represent an indefinite number of arguments as an array.

Your code so far

const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
  "use strict";
  // change code below this line
  const [,,] = list; 
  const arr = rest ;
  // change code above this line
  return arr;
const arr = removeFirstTwo(source);
console.log(arr); // should be [3,4,5,6,7,8,9,10]
console.log(source); // should be [1,2,3,4,5,6,7,8,9,10];

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36.

Actually, the usage of “rest operator” is correct when you’re referring to the left side of a destructuring assignment.

Long answer: the spec refers to the in [] = bar as AssignmentRestElement, so I’d say “Rest Operator” is mostly correct here – but since ... is not technically an operator, we’d actually want to call it “Rest Syntax” to be fully correct. Still, out in the real world, it’s very commonly called the “rest operator”, so FCC is just using the typical term of the art here.

1 Like
function(a, b, {} // rest
const [a, b,] = bar; // rest
const bar = []; // spread
1 Like

thank you for the help chuck!

thank you jenovs. I will store this!