compare and contrast .forEach and .map code example
Example: difference between foreach and map in js
forEach() just loop through the elements. It's throws away return values and always returns undefined.The result of this method does not give us an output .
map() loop through the elements allocates memory and stores return values by iterating main array
Example:
var numbers = [2,3,5,7];
var forEachNum = numbers.forEach(function(number){
return number
})
console.log(forEachNum)
var mapNum = numbers.map(function(number){
return number
})
console.log(mapNum)
map() is faster than forEach()