Immediate function using arrow function
let c = (function (a, b) {
  return a + b;
} ());

This can be expressed as an arrow function

let c = ((a, b) =>(a + b) ());

I understood that it was like this.

However, in the following cases, I investigated for about 3 hours.
I couldn't find a description of whether the search was bad.

An example of an immediate function that has been given a value in advance
let d = (function (a, b) {
  return a + b;
} (1,2));
console.log (d);// 3

How would this be represented by an arrow function?

By the way, in the following cases, it is processed as aString literal

Processed as a function (modified after pointing out)

let d = ((a, b) =>(a + b) (1,2));
console.log (d);

The output result is as follows.
(a, b) =>(a + b) (1,2) // typeof (d) = function

In order for this output to be the expected number "3",
How should it be expressed using an arrow function?

Thanks for your response.
  • Answer # 1


    In the following cases, it is processed as a String literal

    Not. This is afunctionthat calls(a + b)with the argument(1, 2)to get the result >

    Change the break position so that you can see the parenthesis of the function call.

    let d = ((a, b) =>(a + b)) (1,2);

  • Answer # 2

    So difficult Without thinking

    let d = ((a, b) =>a + b) (1,2);
    console.log (d);

    The body is "(a, b) =>a + b". Enclose this in parentheses and specify the argument in parentheses


    If you repeat the same process, you can do it without writing multiple arguments

    let d = ((... a) =>a.reduce ((x, y) =>x + y)) (1,2,3,4) ;
    console.log (d);// 10