This function doesn't call a function, it returns a function.
This code is creating a new unary function where the original binary (greater than) operator's right-hand operand is prebound to a specific value.
In lambda calculus this binding is known as currying.
In Javascript the binding happens because the supplied value of the parameter x
in greaterThan
is permanently retained in the scope of the inner function (or "closure") that is returned.
So, when you call:
var greaterThanTen = greaterThan(10);
what you now have is a new function (named greaterThanTen
) which always compares its single parameter to the bound value of 10.
Hence:
greaterThanTen(9);
will return false
.