DEV Community

Discussion on: What is Map, Reduce, and Filter in JavaScript?

Collapse
 
jonrandy profile image
Jon Randy 🎖️

The default value is actually optional in reduce - if omitted, the accumulator will be set to the first item of the array and the process will continue from the second item. So, providing your array is not empty, you can omit the , 0 from your example code and it will still work... and actually be more efficient.

Collapse
 
whyafan profile image
Afan Khan

Oh, thanks for letting me know. If the default value is 0, then I would definitely not mention it fequently. I believe it is still important for me to add that for beginners to know the initial value of the accumulator :)

Collapse
 
jonrandy profile image
Jon Randy 🎖️

The default value isn't 0