This function
function mapForEach(arr, fn) {
var newArr = [];
for (var i = 0; i < arr.length; i++) {
newArr.push(
fn(arr[i])
)
};
return newArr;
}
var arr1 = [1, 2, 3];
is invoked by
mapForEach(arr1, function (item) {
return item * 2;
}); // [2,4,6]
and is not invoked by this variable declaration
var arr2 = mapForEach(arr1, function (item) {
return item * 2;
});
yet is invoked when logged to the console
console.log(arr2); // [2,4,6] in the console
why isn't invocation here necessary?
console.log(arr2());
I'm still not clear how this differs from
function foo () { return 2 === 2 };
logs function definition
console.log(foo); // function foo() { return 2 === 2 }
invoked in log function, logs return value
console.log(foo()); // true