What is the difference between globalArray and foreachArray object in this below code? and which scenario we need to use the foreachArray object instead of globalArray?
var globalArray= ['Apple', 'Banana'];
globalArray.forEach(function(item, index, foreachArray) {
console.log(foreachArray);// result is ['Apple', 'Banana'];
console.log(globalArray);// result is ['Apple', 'Banana'];
});
forEach()is the array that's being iterated itself. That's very useful if you want to follow a pure-function approach and not rely on "external" (accessible-via-closure) variables.follow a pure-function approach??['Apple', 'Banana'].forEach