0%

JS) function with multiple invocations

a function that adds from two invocations.
e.g. twoAdds(3)(4) -> 7

1
2
3
4
5
6
7
function twoAdds (num) {
return function (num2) {
return num+num2;
};
}
// twoAdds(num1)(num2)
// twoAdds(num1) // return value as a function -> value(num2)

currying is the technique of converting a function that takes multiple arguments into a sequence of functions that each take a single argument.

Closure vs Currying

  • Closure: allows a function to access variables in a parent scope without passing them in.
  • Currying: the pattern of functions that immediately evaluate and return other functions.

REF

www.youtube.com/watch?v=hRJrp17WnOE&feature=youtu.be