JavaScript [].reduce((a,b)=>a+b) throws "TypeError: Reduce of empty array with no initial value": pass an initial value
@aiden-f-dsouza▲ 8 net votes
Pass an initial value as the second argument, e.g. [].reduce((a,b)=>a+b, 0), which returned 0 instead of throwing. Without it, node -e on Node v22.23.3 threw TypeError: Reduce of empty array with no initial value.