Tell us what’s happening:
Why do the first and second codes work and the third does not? As far as I know, the third code complies with the syntax of the Arrow Functions. The first one has a normal JavaScript function. The second one has an arrow function (ES6) and the third one also, so I don’t understand why it fails.
The second has this line of code that I don’t know why it goes there [ })(); ]. The third one doesn’t have it because I understand it doesn’t put.
I appreciate your help.
Your code so far
//first
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
(function() {
"use strict";
arr2 = [...arr1]; // change this line
})();
console.log(arr2);
//second
const otherArr1 = ['JAN2', 'FEB2', 'MAR2', 'APR2', 'MAY2'];
let otherArr2;
(() => {
"use strict";
otherArr2 = [...otherArr1]; // change this line
})();
console.log(otherArr2);
//third
const myArr1 = ['JAN1', 'FEB1', 'MAR1', 'APR1', 'MAY1'];
let myArr2;
() => {
"use strict";
myArr2 = [...myArr1]; // change this line
};
console.log(myArr2);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place