Did you know about currying function in JavaScript? If not, this article is suit best for you. Let's learn about currying function in Javascript.
Currying is an advanced technique that you should know when facing function in JavaScript. In normal conditions, JavaScript arrow functions are written like this.
const multiply = (a,b) => a*b
From the code above, we can understand that the function is used for multiplying two variable a
and b
and display the result. But let we move into one condition when currying is used. I have the console program like this
console.log(multiply(5)(6))
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.
The essential JavaScript concepts that you should understand - For successful developing and to pass a work interview
You may not know about these tips 7 Simple JavaScript Tips for Optimizing Your Code
Hire dedicated JavaScript Developers who are proficient in AngularJS, ReactJS, NodeJS, & VueJS frameworks. Get flexible hiring models as per your business requirements.
In this article, I am going to talk about Javascript Pro Tips. Please learn how to write solid modern Javascript and avoid bad code from the olden days.
JavaScript Shopping Cart - javascript shopping cart tutorial for beginnersBuy me a coffee 🍺 https://www.paypal.com/paypalme/ziddahSource Code: https://bit....