# Functional Programming: How to use Currying in JavaScript with Examples

**URL:** <https://forum.freecodecamp.org/t/functional-programming-how-to-use-currying-in-javascript-with-examples/19476>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [July 11, 2016, 9:20pm UTC](https://forum.freecodecamp.org/t/functional-programming-how-to-use-currying-in-javascript-with-examples/19476 "2016-07-11T21:20:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [July 11, 2016, 9:20pm UTC](https://forum.freecodecamp.org/t/functional-programming-how-to-use-currying-in-javascript-with-examples/19476/1 "2016-07-11T21:20:23Z")

</div>

It is the act of taking a function with more than one argument and converting it into an equivalent function that takes a single argument. This is based on returning partially applied functions.

**Original**

```javascript
function add (verb, a, b) {
   return "The " + verb + " of " + a + ' and ' + b + ' is ' + (a + b)
 }

 add('sum', 5, '6')
   //=> 'The sum of 5 and 6 is 11'

```

**Curried Version**

```javascript
function addCurried (verb) {
    return function (a) {
      return function (b) {
        return "The " + verb + " of " + a + ' and ' + b + ' is ' + (a + b)
      }
    }
  }

  addCurried('total')(6)(5)
   //=> 'The total of 6 and 5 is 11'

```

Currying by hand would be an incredible effort, but its close relationship with partial application means that if you have left partial application, you can derive currying. Or if you have currying, you can derive left partial application.

Here’s a function that curries any function with two arguments:

```javascript
  function curryTwo (fn) {
    return function (x) {
      return callFirst(fn, x)
    }
  }

  function add2 (a, b) { return a + b }

  curryTwo(add2)(5)(6)
   //=> 11

```

---

<div class="post-metadata">

**Author:** ![anon52159105](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@anon52159105](https://forum.freecodecamp.org/u/anon52159105)\
**Post date:** [August 7, 2017, 1:29am UTC](https://forum.freecodecamp.org/t/functional-programming-how-to-use-currying-in-javascript-with-examples/19476/2 "2017-08-07T01:29:33Z")

</div>

Closed on August 7, 2017, 1:29am UTC


