Putting a minus sign infront of function

Viewed 381

What does putting a minus sign in front of a function do?

For example:

return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
1 Answers

It negates the value that descendingComparator(a, b, orderBy) returns, just like the - in -x negates the value that x contains. In context, what it's doing is reversing the order of the sort (presumably this is within an array sort callback or similar).

Related