What does reduce do in javascript

broken image

But for me, the trick was to understand that the result of each run of the callback function will be stored in the first argument it takes, this little a or accumulator. If used postfix, with operator after operand (for example, x- ), the decrement operator.

broken image

It performs BigInt decrement if the operand becomes a BigInt otherwise, it performs number decrement. It first coerces the operand to a numeric value and tests the type of it. It can be a bit confusing at the beginning. reduce() method combines each element of an array, using a specified reducer function, and returns a single value. The - operator is overloaded for two types of operands: number and BigInt.

broken image

Reduce() is a powerful method that can be used to transform data in an array in many ways.

broken image