【发布时间】:2019-05-24 22:49:38
【问题描述】:
得到关于这个reduce函数的错误信息
一开始有这个
const populationTotal = 0;
let populationTotal = zooAnimals.reduce((populationTotal, populationAmount) => {
return populationTotal + populationAmount.population;
}, 0);
console.log(populationTotal);
现在试试这个
const populationTotal = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const reducer = (populationTotal, 10) => populationTotal +
console.log(populationTotal.reduce(reducer));
收到 SyntaxError 错误:分配给右值 (190:34)
【问题讨论】:
-
第一个错误:我得到的是 Uncaught SyntaxError: Identifier 'populationTotal' has been declared
标签: javascript arrays constants reduce