When I have the following:
var anyn = [1,2,3,4,5,6,7,8,9,10];
function hacerAlgo(elemento) {
console.log(elemento)
}
anyn.forEach(hacerAlgo);
I know it works like this, but I want to know why and how this is called, I would like more examples and documentation, I mean the part of:
anyn.forEach(hacerAlgo);
As far as I know, a function to receive a parameter must be called in this case:
hacerAlgo(parametro);
but here you never do that .. then?
According to what I've researched, I think it works as just a reference , so the forEach
sends each of the elements of the array
and the function hacerAlgo
, is like the reference to which you will pass by parameters, but I would like more examples apart from forEach
, and if I am right or not.