Currying in JavaScript: Improving Code Reusability

🔥 Mock Interview Question of the Day – What is Currying in JavaScript? Today in my mock interview, I was asked: 👉 What is Currying? Here is my answer: 📌 Currying is a technique in JavaScript where a function takes one argument at a time and returns another function until all arguments are received. Instead of: function add(a, b, c) { return a + b + c; } add(2, 3, 4); // 9 We write: function add(a) { return function(b) { return function(c) { return a + b + c; } } } add(2)(3)(4); // 9 💡 Why we use Currying? Improves code reusability Helps in functional programming Makes function more modular Useful in partial application 🚀 Example: function multiply(a) { return function(b) { return a * b; } } const double = multiply(2); console.log(double(5)); // 10 Here, double is a reusable function. 📚 Learning every day. 💪 Improving step by step. 🎯 Goal: Become a strong Frontend Developer. #JavaScript #FrontendDeveloper #WebDevelopment #MockInterview #Learning

To view or add a comment, sign in

Explore content categories