Consider the following code.
Notice that a>
function b()
doesn't exist until the call a(function b() {});
is executed.
JS doesn't search the code for functions, that way. Also, function b() {}
isn't a function declaration, you're merely passing it as a parameter. The only way to access that function would be within function a()
:
function a() {console.log(arguments[0])}
a(function b() {});
//function b() {}
However, this does not mean that you can actually call b()
inside a()
, since b()
is defined in the scope of a
's function call, not in the function itself. Basically, the name b
is useless.