© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Subha Chanda
Technical Writer | Developer
JavaScript Map, Reduce and Filter Functions Introduction Arrays are important Data Structures in programming. All the methods which we are going to discuss in this article will iterate over an array and return a new array based on the result function...
Michael Geary
const sum = arr.reduce((result, item) => { result = result + item; return result; });
Since result is local to the callback, you can simplify this to:
result
const sum = arr.reduce((result, item) => { return result + item; });
Thank you for the suggestion. 😊 I was thinking to use this code, const sum = arr.reduce((result, item) => result + item); But because it's not much beginner-friendly, so I chose to go with the one above.
Bolaji Ayodeji
Software Engineer, Teacher, and Developer Advocate.
Really insightful, thanks for sharing.
Michael Geary
const sum = arr.reduce((result, item) => { result = result + item; return result; });Since
resultis local to the callback, you can simplify this to:const sum = arr.reduce((result, item) => { return result + item; });