Skip to content Skip to sidebar Skip to footer

What Is Double Arrow Function?

What is 'let x= something1 => something2 => something3' ? I have this code and I'm failing to understand what does it do. const myReducers = {person, hoursWorked}; const comb

Solution 1:

let x= something1 => something2 => something3 is almost same as the following:

let x = function (something) {
  return function (something2) {
    return something3
  }
}

The only difference is, arrows have lexical binding of this, i.e. binding in compile time.


Solution 2:

An arrow function is

someParameters => someExpression

So, what is

someParameters => someThing => someThingElse

???

Well, by simple stupid "pattern matching", it's an arrow function, whose body (someExpression) is

someThing => someThingElse

In other words, it's

someParameters => someOtherParameters => someExpression

There's nothing special about this. Functions are objects, they can be returned from functions, no matter if those functions are written using arrows or the function keyword.

The only thing you really need to know to read this properly is that the arrow is right-associative, IOW that

a => b => c === a => (b => c)

Note: An arrow function can also have a body consisting of statements as well as a single expression. I was specifically referring to the form the OP is confused about.


Post a Comment for "What Is Double Arrow Function?"