# Why does, "return", not work here?

**URL:** <https://forum.codewithmosh.com/t/why-does-return-not-work-here/13334>\
**Category:** JavaScript\
**Created:** [June 28, 2022, 3:40pm UTC](https://forum.codewithmosh.com/t/why-does-return-not-work-here/13334 "2022-06-28T15:40:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dalare](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@Dalare](https://forum.codewithmosh.com/u/Dalare)\
**Post date:** [June 28, 2022, 3:40pm UTC](https://forum.codewithmosh.com/t/why-does-return-not-work-here/13334/1 "2022-06-28T15:40:35Z")

</div>

Hi all,

I was just curious to know why, “return”, wont work here but, “console.log(value)”, works?

## Thanks.

let numbers = [1,2,3,4,5,6];

let returnNumbers = numbers.forEach(value =\> {  
return value;  
});

console.log(returnNumbers);

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [June 28, 2022, 9:40pm UTC](https://forum.codewithmosh.com/t/why-does-return-not-work-here/13334/2 "2022-06-28T21:40:08Z")

</div>

Hi,

The return value of `forEach` is `undefined`;  
You cannot return a sum for instance with `forEach`.

Let imagine it would return `value`, it would crush that value for every new value processed and actually display the last one I believe.

Here are 2 options to return a sum for example:

```nohighlight
let numbers = [1,2,3,4,5,6,7,8,9];

let returnNumbers = 0;
numbers.forEach(v => {
	returnNumbers += v;
});

let result = numbers.reduce((a,b) => a+b);

console.log(result); // 45
console.log(returnNumbers); // 45

```

Regards
