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.
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?
-
Answer # 1
-
Answer # 2
So difficult Without thinking
let d = ((a, b) =>a + b) (1,2); console.log (d);
Thoughts:
Reference
The body is "(a, b) =>a + b". Enclose this in parentheses and specify the argument in parenthesesIf 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
Related articles
- embed a function with javascript argument in html generated from javascript
- javascript - i want to pass a string argument to the html onclick function
- javascript function becomes undefined
- javascript - is it possible to activate the scroll function with scroll-snap? ??
- javascript - i want to express a function registered as a value using a method name for an object with an arrow function
- javascript - i want to reduce the image of the preview function
- javascript - uncaught typeerror: 〇 〇 i want to solve is not a function
- about side effects of javascript function
- 16 mass roulette with javascript (implementation of function not selected again)
- javascript - i want to understand the filter method with the function function
- javascript - i want to implement the in-page jump function based on the information read by ajax
- i want to implement an accordion opening/closing function with javascript
- javascript - i want to implement a chat function using action cable
- how to pass a string as a function argument in c ++
- javascript - i want a function that returns a string to work in return
- python - when none is assigned to the formal argument of the function definition
- javascript - about the processing mechanism of the function
- about javascript random function
- [javascript/rails] follow function cannot be implemented asynchronously
- javascript - please tell me how to execute a function with undetermined arguments
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.