I recently came across this this in a unit test:
This is weird syntax; what does it mean?
First, you can create an arrow function in a few different ways. This is how I might do it commonly:
I like using parenthesis to surround the arguments. But, they are not required. If you only have a single argument you can leave out the parenthesis:
Then, for an arrow functions where you don't care about the arguments, you can use a single character variable, like what I wrote about earlier this week. Use the underscore ('_') like what we started with:
This is intended as short hand for saying "I don't care what the argument is; I'm going to ignore it inside this function." My personal feeling is that the short hand does not communicate that, at least not universally.
As such my preference is to use parenthesis with no variable input into the function:
The reason for the short hand is that it is one less character to type. But, I'd argue that the latter approach with parenthesis is more readable. I'm not in a position where I have to cut down on keystrokes that significantly.
How about you?