The objective is to print the values form the inner most function.
Is there a way i can acess the inner function
To use inner you need to return it in some way:
You can define outer() like this
function outer(arg1) {
let var1 = 10;
function middle(arg2) {
let var2 = 20;
function inner() {
let var3 = 30;
console.log(arg1, var1, arg2, var2, var3);
}
return inner();
}
return middle;
}
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.
i tried doing that but output comes out to be para1. Ideally the output should be para1, 10, para2, 20, 30 because
when the control is on line 15 the outer function gets called and we pass para1 to it and x becomes middle function
when line number 3 is executed due to closure the middle function has acess to arg1 and var1, it would be similar for inner function then why do i get para 1 as output
I don’t know exactly what the issue is with console logging every variable in one line but if you write them in separate statements they will work like this:
console.log(arg1);
console.log(var1);
console.log(arg2);
console.log(var2);
console.log(var3);