In Chrome Dev Tools, the following logs NaN
rather than the desired 526
.
const nums = [7,2,11,4,9,0,1,7,14,3];
const sumSquares = nums.map((element)=>{Math.pow(element, 2)}).reduce((a, b)=>a + b, 0);
console.log(sumSquares);
// console logs `NaN`
The issue appears to lie with the formatting of .map
‘s arrow function. Here I have used parenthesis and curly braces, when neither was necessary. However, I wouldn’t expect this to break my function. When removing the parenthesis and curly braces, the console logs 526
, as desired:
const nums = [7,2,11,4,9,0,1,7,14,3];
const sumSquares = nums.map((element)=>Math.pow(element, 2)).reduce((a, b)=>a + b, 0);
console.log(sumSquares);
// console logs `526`
Why do curly braces change the output here?