check this,
same question answered in stack over flow [
^]
In simple way,
function greaterThan(outer) {
function innerFunction(inner) {
return inner > outer;
};
return innerFunction;
}
console.log(greaterThan(10)(11));
greaterThan
is a function which takes an input and returns a
Function
(innerFunction -> which takes an input and
returns
a
bool
value by comparing
outer
and
inner
arguments )
so by calling greaterThan(10), it will instantiate the function with outer value as 10 and it returns the innerFunction object which can be invoked as below. Since a
Function
is
returned, the life time of the outer variable value (10) will be present in the inner function till the window is closed.
normally,
Function
is called by the syntax
FunctionName(args,...)
var outerFunction = greaterThan(10);
console.log(outerFunction(11));
console.log(greaterThan(10)(11));
to know more about function and closures refer :
JavaScript Function Closures[
^]
Closures - JavaScript | MDN[
^]