What is function currying in JavaScript ?
Function currying is a way to change a function that takes multiple arguments, like sum(a, b), into a series of functions that each take one argument, like sum(a)(b).?
The end result is the same, but it can make the code more reusable and easier to understand.
Look at this simple example,
when we call the function sumCurry(2), it returns a closure. which is why the inner function which is returned from function sumCurry() can access the variable ‘a’ and adds it to param ‘b’ and return the result a+b when we invoke it (sumCurry(2)(3)).
So next time you find yourself writing a function that takes multiple arguments, consider using function currying to simplify your code and make it more flexible.
Have you ever used function currying in your code? What were your experiences with it? Share your thoughts in the comments!!
Hello Siva... We post 100's of job opportunities for developers daily here. Candidates can talk to HRs directly. Feel free to share it with your network. Visit this link - https://jobs.hulkhire.com And start applying.. Will be happy to address your concerns, if any
Software Engineer | IIIT-Nuzvid
1 年Function currying is named after an American mathematician named Haskell Curry who developed the concept :)