So many time we got confused in currying and closure JavaScript functions just because both uses functions inside function.
So This is the answer of your question.
First I will explain What is closure in JavaScript ?
Creating a closure is nothing more than accessing a variable outside of a function's scope. Please note that a function inside a function isn't a closure. Closures are always use when need to access the variables outside the function scope.
Here is an example of closure function:
1 2 3 4 5 6 7 |
function apple(x){ function google(y,z) { console.log(x*y); } google(7,2); } apple(3); |
Answer will be 21. So here inside google function we are able to access the variable x which is outside the scope of the function google(). ...