Working of functions

At timestamp 6:52…first the outer function is called which returns the inner function and that in turn gets stored in variable x…so if at this stage we run it, I mean if we only call the outer function and DO NOT do x(‘param2’) then will anything be printed??? If not, then why is that so?..if the outer function was called…so did it not execute the inner function despite it being part of outer function…can you explain what exactly is happenning here

As per the code :

     function outer(arg1){
          let var1=10;
          function inner(arg2){
             let var2=20;
             console.log(var1,arg1,var2,arg2);
          }
          return inner;
        };
        let x = outer('param1');
         x('param2');
  • The outer function is called and the return value is stored in the variable x.
  • As per outer function definition it returns the inner function as its return value.

Note : the inner function is not called here it is just simply defined inside the outer function and is returned.

  • When we define variable x we are calling the outer function
  • No since the console statement is in the inner function and we are omitting the calling the inner function hence nothing would be printed in that case. The inner function will not be called hence nothing will be printed.
  • In the outer function the inner function is just defined and returned but not called hence the inner function will not be called or executed while we call the outer function.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.