Skip to content

What do multiple arrow functions mean in JavaScript? #317

Discussion options

You must be logged in to vote

const add = (x, y) => x + y
add(2, 3) //=> 5

Here it is again in curried form …

const add = x => y => x + y

Here is the same1 code without arrow functions …

const add = function (x) {
return function (y) {
return x + y
}
}

Focus on return

It might help to visualize it another way. We know that arrow functions work like this – let's pay particular attention to the return value.

const f = someParam => returnValue
So our add function returns a function – we can use parentheses for added clarity. The bolded text is the return value of our function add

const add = x => (y => x + y)
In other words add of some number returns a function

add(2) // returns (y => 2 + y)
Calling curried functions

So …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ethan-chen-gr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants