const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34]; const squareList = (arr) => {
"use strict";
const squaredIntegers = arr.filter( (num) => num > 0 && num % parseInt(num) === 0 ).map( (num) => Math.pow(num, 2) );
return squaredIntegers;
};
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
Asked
Active
Viewed 300 times
-1

Ankit Agarwal
- 30,378
- 5
- 37
- 62

homecookedinc
- 11
- 1
-
Should do some reading up on how variable scope works in javascript – charlietfl Jul 07 '18 at 12:31
1 Answers
3
Because one const
is a local variable of the squareList
function, the other const
is a global variable holding a squareList. Using the same variable name twice in different scopes is called shadowing, thats sometimes useful but it can also create confusion like in this case.

Jonas Wilms
- 132,000
- 20
- 149
- 151