Hi, so I’m learning a bit about ES6, and I’m confused about const newArray in the code below.
const array = [1, 2, 3, 50];
const double = [];
const newArray = array.forEach((num) => {
double.push(num * 2);
})
console.log(double);
I understand what this code does, and the ES6 arrow syntax, but I’m confused about what newArray actually is after this is run. If I run this code, it returns a doubled array in double, but then newArray is unidentified. It has no value, and it’s not a function, I’m confused. The code would run the same without it:
const double = [];
array.forEach((num) => {
double.push(num * 2);
})
Can someone help me understand why we assign this constant?