Ask the boss to help solve the problem of js, which is passed by the parameter.

var pow2 = make_pow (2); indicates that parameter n is passed in, but why is it that parameter n is not assigned when pow2 is printed?

Mar.12,2021

var pow2=make_pow(2);//pow2function
//:
pow2();

my understanding: console.log is a string of printed references, and the pow2, parameter is not running and is a formal parameter at this time. And the assignment you want is what happens at run time.


prints out a function that prints whatever it is, and does not automatically assign values according to the context of context . A simple and intuitive example:


make_powJS:

var pow2=make_pow(2);
console,log(pow2(3)); // 9

as to why pow2 can save the value of n, it involves the problem of closure.

Menu