Today I Learned: currying is possible in Javascript ES6 (ES2015).
Javascript has always considered functions to be first-class citizens of the language, meaning we can pass them around as input for other functions. Currying allows us to create temporary stateful copies of other (stateless template) functions, which we then can apply to local variables.
As far as I can tell, currying was created both to accommodate languages that limit the amount of arguments (input passed into a function) to 1, and to allow functions to remember variable contents without having to write out a variable that remembers it, giving it the pretense of being stateless. (In functional programming, people harp on writing stateless code, but also love currying.)
So here's some code:
const letters = ["a", "b", "c"];
const numbers = [0, 1, 2];
const concat = (y) => (x) => x+y;
numbers.forEach(i => {
  let c2 = concat(i);
  console.log(c2(letters[ i ]));

Open in new window

The output:

Open in new window

You can try this out yourself over on SoloLearn, for instance, where I've saved a runnable version of above code sample.
Happy currying!

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month