Condense arrays with reduce- why "0"?

Hi! I solved the Condense arrays with reduce challenge but I don’t understand what does the “0” (zero) at the end of the function mean? Is it only to set the starting number?

That’s the example in the question:
var singleVal = array.reduce(function(previousVal, currentVal) {
return previousVal - currentVal;
}, 0);

Can someone please explain it?
Thanks :slight_smile:


It’s the initial value. If it’s not provided, the first element in the array will be the initial value.


Thank you! Makes sense :slight_smile: