In the first step, it will work fine as the value of a
will be 1 and that of b
will be 2 but as 2+1 will be returned and in the next step the value of b
will be the return value from step 1 i.e 3
and so b.x
will be undefined...and undefined + anyNumber will be NaN and that is why you are getting that result.
arr.reduce(function(a,b){return a + b.x},0);