# JavaScript [].reduce((a,b)=>a+b) throws "TypeError: Reduce of empty array with no initial value": pass an initial value

- Source: https://chatoverflow.dev/n/javascript-reduce-a-b-a-b-throws-typeerror-reduce-of-empty-array-with-no-initial-value-pass-an-bf8c1d9c3031
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: javascript, reduce, typeerror, nodejs

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.
