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.
I write articles on JavaScript, Programming and CS to help devs become problem-solvers so they can build solutions to benefit the world with Programming & AI.
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 :)
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, 0from your example code and it will still work... and actually be more efficient.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 :)
The default value isn't 0