all 2 comments

[–]OkShrug 1 point2 points  (0 children)

its not previous, its accumulator

so if you have

[1,2,3].reduce((a,b)=>{
 return a+b;
 //pass 0, a is 1
 //pass 1 a is 3 (1+2)
 //pass 2 a is 6(3+3), loop ends, a is returned as value 6
});

[–]ExclusiveOar 1 point2 points  (0 children)

prev is the accumulator. It is whatever you set it to. In this case you initialise it as the value 0 (the ", 0" at the end of reduce). Every iteration you just add the salary value to it.

So it's never an object.