About the parameters of the self-executing function?

for (var iMago dint arr = []; I < = 3pi) {

arr.push(
  (function(h){
    return function(){
      console.log(i);
    }
  })(i)
);

}
arr [0] (); / / 4
is also a question asked today, that is, are there any requirements for the parameters of anonymous functions? I used to understand that h is just a formal parameter and can be written as anything. But the result is not 0 as imagined, but 4. After changing h to I, the result is 0. What"s going on? shouldn"t that h be just a parameter

?
Mar.15,2021

these two functions are anonymous functions, so I become called functions and inner functions.
the parameter of the outer function is h , but you do not use the parameter h in the outer function body, so each generated inner function uses the final variable I . Each time function () {console.log (i)} is returned.
and if you use the following form:

 

console.log (h) Thank you

console.log (i), the automatic execution function you write is meaningless

Menu