I had started to learn JavaScript for web development and I am currently stuck at a point in the callback function. The problem is that I can't understand how arguments are passed in JavaScript.
CODE:
const arr = [1, 2, 3, 4, 5, 6, 7, 8];
function myfunc(value){ //i had set a parameter 'value'
console.log(value); // i had printed the 'value'
}
arr.forEach(myfunc); // i had not passed any argument in myfunc
I am really confused about how myfunc (value) gets the 'value' parameter from in forEach function or any functions like:
const numbers1 = [45, 4, 9, 16, 25];
function myFunction(value) { //myFunction has parameter 'value'
return value * 2;
}
const numbers2 = numbers1.map(myFunction); /* here, how value arguments are passed to
myFunction? */