Simple question - why
[1,2,3,4].forEach(console.log)
works fine,
let g = f => [1,2,3,4].forEach(f);
g(console.log);
works fine, but
let h = [1,2,3,4].forEach;
h(console.log)
throws Uncaught TypeError: Array.prototype.forEach called on null or undefined ?
let arr = [1, 2, 3, 4], h = arr.forEach.bind(arr);[1,2,3].forEach(e => console.log(e)). The last example doesn't invokeArray.prototype.forEach.forEachexpect a callback as a parameter, In your first and second functions you are passing that,console.log, andfas a parameter