DEV Community

Lukas Polak
Lukas Polak

Posted on • Updated on • Originally published at lukaspolak.com

JavaScript currying

Currying is when a function returns another function until arguments are fully supplied. A curried function can take multiple arguments, but only one at a time. A partially applied function is a function which has been applied to some, but not yet all of its arguments. In other words, a curried function is a function that has some arguments fixed inside its closure scope. Every curried function returns a partially applied function, but not every partially applied function results from a curried function.

Given a function with n parameters, the curried version will take one argument at a time and return a function that takes the next argument and so on. The last function returns the result of applying the function to all of its arguments.

Top comments (0)