Following is the code, which is working fine -
const print = x => {
console.log(x)
}
const result = [1,2,3,4].forEach(print)
console.log(result)
But when I am trying to pass another variable to print2
function I am getting an undefined
error.
const print2 = (x, y) => {
console.log(x * y)
}
const result = [1,2,3,4].forEach(print2(x, 10))
console.log(result)
I am going through the callback function chapter, so please spare me if something very common I missed here.