Consider a simple scenario where you have an array of numbers and you want to return the sum of all elements in that array.
We will see that it’s a solution in ES5 and that it’s equivalent in ES6 to using reduce helper.
ES5 Code
The above code will return an output of 150.
ES6-Equivalent Code Using Reduce
The above code will also return output as 150.
You can write the same code in ES6 using Reduce Helper with arrow function as follows, which will return the same output.
#es6 #es5 code #es6-equivalent code