Consider myArray as an array of objects.
Are these two pieces of code equivalent ?
myArray.forEach((item) => {
return doAnAction(item);
});
myArray.forEach((item) => {
doAnAction(item);
});
Is there any of them that is better in terms of syntax? If yes, why ?
.forEach()does not use the return value of it's callback. For more information, you can always check MDN. It's a great resource.return. If you asking about code style then 1) opinion-based questions are off-topic on SO 2) Personally, I prefer the latter because addingreturnimplies you're using the return value, which there is none.