const multiply = (a,b) => a*b
From the code above, we can understand that the function is used for multiplying two variable
b and display the result. But let we move into one condition when currying is used. I have the console program like this
By using the function above, the program will be error, because the (6) variable is not a function. To make the program work, we need the currying function to do his job. So the program is written like this
const multiply = (a) => (b) => a * b
If we run the code again, the output will print the correct answer. Do you know why it works?
Simple, currying is the technique of converting a function that takes multiple arguments into a sequence of function that each take a single argument. This function can helping us to removing repetition. Here is the example that I got from simonschwartz.