0

While coding, i faced a problem in resolving variables in a code similar to the code below:

 function foo(callback) {
     callback();
 }

foo( function(parameter) { 

    // how variables are resolved here? what is the outer scope?  

    console.log('helloWorld'); 
});

The questions are:
how variables are resolved inside the anonymous function defined in foo parameters spot?
I know that javascript resolve variables using the lexical scope, but in that function, what is the outer scope ?

Moody
  • 43
  • 1
  • 7
  • 1
    The outer scope is the same block that the `foo( function(parameter) { ` call is on - anything defined in that block or an ancestor block will be visible inside the call to `foo` – CertainPerformance May 24 '20 at 18:24
  • 1
    "lexical" means the scope that the function is defined in, not the one that it is called from. – Bergi May 24 '20 at 19:03
  • its all clear now, thank you so much for your help – Moody May 24 '20 at 19:53

0 Answers0