DEV Community

Cover image for JS interview in 2 minutes / Currying πŸ₯˜

JS interview in 2 minutes / Currying πŸ₯˜

Nick K on May 14, 2021

Question: What is currying in JavaScript? Quick answer: It is a technique used to convert a function that takes multiple arguments into a chain of...
Collapse
 
kspeakman profile image
Kasey Speakman

Currying is mainly a way to setup a function for easier partial application -- providing only some of the function arguments. You can do partial application without currying, but it is less convenient.

// currying partial application
let add = a => b => a + b
let add2 = add(2)
add2(7)
// 9

// non-currying partial application
let add = (a, b) => a + b
let add2 = b => add(2, b)
add2(7)
// 9
Enter fullscreen mode Exit fullscreen mode
Collapse
 
hexnickk profile image
Nick K

Thanks πŸ™ Added a note with a link to this comment to the post itself.

Collapse
 
chriskingwebdev profile image
ChrisKingWebDev

This is a great quick explanation. I made an account to follow you so I can get all the 2 minute interview reviews. Good stuff.

Collapse
 
hexnickk profile image
Nick K

It is so nice and inspiring to hear ✨ Glad you like these articles!

Collapse
 
siddharthshyniben profile image
Siddharth

This is actually wrong as a curried function can take any number of arguments, not just 1. Good explanation though πŸ‘