ES6 - Destructuring via rest elements

Tell us what’s happening:

Why my code don’t run if I don’t add const before [a, b,… shorterList] ? It runs on other consoles and give the desired result. So, what’s the logic here ?

Your code so far

function removeFirstTwo(list) {
 [a,b,...shorterList] = list
  return shorterList;

const source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const sourceWithoutFirstTwo = removeFirstTwo(source);

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Mobile Safari/537.36

Challenge Information:

ES6 - Destructuring via rest elements

Editor on page runs in the strict mode, this means all variables have to be declared.

1 Like

As @sanity mentioned… strict mode requires the declaration. Some more info here:

1 Like