

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is currying in JavaScript?
Currying
Currying is a technique of evaluating function with multiple arguments, into sequence of functions with single argument.In other words, when a function, instead of taking all arguments at one time, takes the first one and return a new function that takes the second one and returns a new function which takes the third one, and so forth, until all arguments have been fulfilled.
Uses of currying function
a) It helps to avoid passing same variable again and again.
b) It is extremely useful in event handling.
syntax:
function Myfunction(a) { return (b) => { return (c) => { return a * b * c } } }
Example
In the following example,since no currying is used, all the parameters were passed at once(volume(11,2,3)) to the existing function to calculate the volume.
<html> <body> <script> function volume(length, width, height) { return length * width * height; } document.write((volume(11,2,3))); </script> </body> </html>
Output
66
Example
In the following example,since currying is used,parameters were passed one by one(volume(11)(2)(3)) until the last function called the last parameter .
<html> <body> <script> function volume(length) { return function(width) { return function(height) { return height * width * length; } } } document.write(volume(11)(2)(3)) </script> </body> </html>
Output
66
- Related Questions & Answers
- What is the currying function in JavaScript?
- Currying VS Partial Application in JavaScript.
- What is NaN in JavaScript?
- What is Debouncing in JavaScript?
- What is lexical this in JavaScript?
- What is function() constructor in JavaScript?
- What is increment (++) operator in JavaScript?
- What is decrement (--) operator in JavaScript?
- What is Conditional Operator (?:) in JavaScript?
- What is typeof Operator in JavaScript?
- What is Modulus Operator (%) in JavaScript?
- What is Multiplication Operator (*) in JavaScript?
- What is Addition Operator (+) in JavaScript?
- What is Assignment Operator (=) in JavaScript?
- What is Comma Operator (,) in JavaScript?