InterviewSolution
| 1. |
What Is Closure In Javascript? |
|
Answer» While you create the JavaScript function within another function and the inner function freely access all the variable of OUTER function. i.e. function ourterFun(i) { The output will get 16 because innerFun() function can access to the argument "i" & variable "var1" but both are define in the outerFun() function that is closure. That means simply accessing variable OUTSIDE of your scope create a closure. // OR Other WAYS While you create the JavaScript function within another function and the inner function freely access all the variable of outer function. i.e. function ourterFun(i) { The output will get 16 because innerFun() function can access to the argument "i" & variable "var1" but both are define in the outerFun() function that is closure. That means simply accessing variable outside of your scope create a closure. // OR Other WAYS |
|