JS — Currying

Aayushi kumar
3 min readMay 29, 2021

What is the Function Currying.?

For that, we have to learn what Function Closure is.?

Closure in simple words “Function that takes multiple parameters one at a time, it takes one argument and returns the series of function that takes one argument each”

The Way to denote the closure Function is as mentioned below:

Closure Function

The simplest solution of the Closure function is to divide the Functions in the nested returning function one into another. As Below:

As per the next standard question looking at the above code one would ask, But what if there come 10 or more arguments. In That case, we can recursively do the same thing for 10,20 or more argument for that sake. As Below:

Recursively returning function

Now We have understood the Closure so let's see what Function Curry Is. Well, the whole article seems to be a built-up around the Curry.

Again back to simple Explanation — “Curry isn’t a function call. It's just function transformation. Transforming function(a,b,d) into a closure function is called Curry”

function curry to closure.

!Important The currying requires the function to have a fixed number of arguments.

Let's Dig deep. Matter of some check only. Try Yourself.

#1. sum(2)(3)(4)();

#2. sum()(3)(4)(5);

#3. sum(3)()(4)(5);

REASON FOR THE POST
We all have used it but as you read the Article heading there might be some changes that you might not recall or frame it's in a sentence what the function curry is.

It happened to me while talking to a few people overcall, they asked me the same question. Initially, due to low network, all I heard was curry and the first thing that came into my mind was ‘Why he is asking about the curry in the middle of an interview’. Later in another call, I understood the full question but then I was blank as I haven’t heard the name before.

Later I googled as most of us do, the next moment I hit my head. “This stupid piece of code is called Function curry. I have been using it all the time.”

--

--

Aayushi kumar

Full-stack Web Developer | Angular | JavaScript | Node.js | MongoDB | MySQL | CMS (First Spirit).