Implement Infinite Currying Multiplication in JavaScript: mul(2)(3)(4)
Understand the step-by-step implementation of Infinite Currying Multiplication in JavaScript with a code example.
Anuj Sharma
Last Updated Feb 21, 2026

Currying in JavaScript provides a way to implement partial functions in JavaScript, and one of the use cases is to implement Infinite currying in JavaScript to calculate multiplication using partial functions, such as mul(2)(3)(4). This is one of the most common JavaScript interview questions.
Implementing Infinite Currying Multiplication in JavaScript
Let's implement a function that performs infinite multiplication using currying. The function should be able to take any number of arguments and return the multiplication of all those arguments. This is known as Infinite Currying Multiplication.
Steps to Implement Infinite Currying Multiplication
- Create a function called
curryMultiplythat takes one argument. - Within the
curryMultiplyfunction, return another function that takes the next argument. - Inside the nested function, multiply the current argument with the accumulated product.
- Return the nested function if there are more arguments to process, or return the accumulated product if all arguments have been processed.
Code Example
function curryMultiply(x) {
let mul = x;
// Multiply and return another function
function inner(y) {
mul = mul * y;
return inner;
}
inner.toString = function() {
return mul;
};
return inner;
}
// Usage
const result = curryMultiply(2)(3)(4)(5);
console.log(result.toString()); // Output: 120
Explanation of the Code
In the above code snippet, we define a function curryMultiply that takes an initial argument x. The inner function inner is returned, which multiplies the current argument with the accumulated product and returns itself to allow chaining means you can call other function using dot (.)
Inner function has access to the mul at any given point of time due to closure in JavaScript. We also override the toString method of the inner function to return the accumulated product when the function is converted to a string.
Real-World Example: Calculating Total Price
Let's consider a real-world example where Infinite Currying Multiplication can be useful. Suppose you need to create a calculator application, where we can have a mul partial function which can used to provide multiplication whenever user enter any number and hit multiplication(*) symbol.
// Calculator example
const mul = curryMultiply(1);
const multiplication = mul(10)(20)(30)(40);
console.log(multiplication.toString()); // Output: 240000
Â
Final thoughts
Practice implementing Infinite Currying Multiplication with different scenarios to solidify your understanding. This knowledge will not only help you tackle interview questions but also improve your problem-solving skills in frontend development.
Learn Next
- Infinite Currying Sum in JavaScript
- Top JavaScript Interview questions
- Promise Polyfill in JavaScript
- Promise.all Polyfill in JavaScript
- 5 Rules to master this keyword in JavaScript
A seasoned Sr. Engineering Manager at GoDaddy (Ex-Dell) with over 12+ years of experience in the frontend technologies. A frontend tech enthusiast passionate building SaaS application to solve problem. Know more about me 🚀
Learn Next
Comments
Be the first to share your thoughts!
No comments yet.
Start the conversation!
Share your expertise
Publish a blog or quick notes on topics you know well — your write-up could be the answer someone needs before their next frontend interview.
Build your portfolio
Help the community
Sharpen your skills
Earn goodies
Other Related Blogs
Implement Infinite Currying Sum: JavaScript Interview Question sum(1)(2)(3)
Anuj Sharma
Last Updated Feb 21, 2026
In this post, we will going to cover the step-by-step implementation of Infinite Currying Sum with a code example. This is one of the most common JavaScript Interview questions.
How to convert HEX to RGB in JavaScript
Anuj Sharma
Last Updated Jul 6, 2026
A quick way to convert HEX to RGB in JavaScript that will help to do the CSS HEX to RGB color conversion programmatically.
How to convert RGB to HEX in JavaScript
Anuj Sharma
Last Updated Jul 6, 2026
A quick way to convert RGB to HEX in JavaScript that will help to do the CSS RGB to HEX color conversion programmatically
Understand Debouncing in JavaScript with Examples
Anuj Sharma
Last Updated Jun 27, 2026
Understand the concept of Debouncing in JavaScript to improve the performance of your web application and optimize the event handling in JavaScript, by limiting API calls or DOM events.
Implement JSON Parse polyfill in JavaScript
Anuj Sharma
Last Updated Jun 15, 2026
Explore the code implementation of JSON Parse Polyfill in JavaScript that can parse a string into valid JSON.
Implement JSON Stringify Polyfill in JavaScript
Anuj Sharma
Last Updated Jun 15, 2026
Explore the detailed explanation of the JSON Stringify Polyfill implementation in JavaScript to prepare for the frontend interviews.
What is javascript:void(0) and How it Works?
Anuj Sharma
Last Updated Jun 15, 2026
A comprehensive explanation about using javascript:void(0) in javascript. When to use javascript:void(0) and how it works with examples of using it with anchor tag.
Understand JavaScript Date Object with Examples (for JavaScript Interviews)
Anuj Sharma
Last Updated Jun 15, 2026
Go through different ways to display dates using javascript date object. It covers examples of date object usage to understand the main concepts of javascript date object.
