Condense arrays with reduce- why "0"?

Condense arrays with reduce- why "0"?
0

#1

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:


#2

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


#3

Thank you! Makes sense :slight_smile: