Currying in JavaScript: Function Composition and Reusability

Interview Question I Was Asked Today: What is Currying in JavaScript? Currying is a technique 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(1, 2, 3); We write: function add(a) { return function(b) { return function(c) { return a + b + c; }; }; } add(1)(2)(3); It helps in: 1)Creating reusable functions 2)Function composition 3)Avoiding repetition 4)Writing cleaner functional code Modern JS version (ES6): const add = a => b => c => a + b + c; Small concept. Big impact in functional programming. 🚀 #JavaScript #Frontend #ReactJS #ReactNative #InterviewPreparation #Development

Both are functional, actually.

Like
Reply

To view or add a comment, sign in

Explore content categories