Currying is a technique that allows you to partially apply the arguments of a function. Instead of passing all arguments at once and getting the final result, you can pass some arguments and receive a new function that will wait for the remaining ones.
As @KevBot mentioned, your example should include the return statement for the second function:
function add() {
let x = arguments[0];
return function s(num) {
return num + x;
}
}
add(2)(3);
ES6 Curried Hello World:
curriedHelloWorld = (greeting) => (name) => `${greeting}, ${name}!`;
curriedHelloWorld("Hello")("Tygar");
You can also uncurry the `curriedHelloWorld` example in reverse:
helloworld = (greeting, name) => curriedHelloWorld(greeting)(name);
helloworld("Hello", "Tygar");