Currying is a powerful pattern in the Javascript language. Many libraries make use of this pattern. It is primarily based on the concept of closures. If you understand scopes and closures well, it would be easy to understand.

It’s a must read for anyone preparing for a front-end/javascript interview. Questions around currying in javascript are highly expected in an interview. So don’t miss it.

In this post, we’ll discuss multiple javascript interview problems around currying - from a simple one to the advanced ones.

Let’s start with a simple `sum` function. All it does - takes 3 arguments, adds them up and returns the sum.

``````function sum (a, b, c) {
return a + b + c;
}

sum(5, 6, 7);
``````

## Problem

Can you rewrite the `sum` function to take arguments like the one shown below?

``````sum(5)(6)(7);
``````

Wow! that’s a weird way to invoke a function. Isn’t it?

It’s called a curried version of the `sum` function.

A lot of candidates get confused when they see problems involving currying. Even the experienced ones. But it’s not as hard as it seems.

#closures #javascript #currying #programming

12.00 GEEK