In order words, what's the advantage of writing this:Listing 1var sortBy = function sortBy(p) {  return function (a, b) {    return a[p] > b[p];  };};Compared to this?Listing 2var sortBy = function sortBy(p, a, b) {  return a[p] > b[p];};Reference.
High order functions: What's the benefit returning a function compared to a value?
javascript;higher order functions
In the first listing you can partially apply sortBy, in the second you cannot. The advantage of partially applying this function is that you can decouple the dependency of which key to sort by from usages of the sort function. See this question for a more complete description of the advantages of currying.For example:const sortByName = sortBy(name)const a = { name: aaron }const b = { name: billy }const c = { name: charlie }sortByName(a, b) // truesortByName(b, c) // trueThis is useful if you need a binary function. For example Array.prototype.sort() takes a binary function as an argument. You could do something like this (if your sort function was implemented according to the spec):[a, b, c].sort(sortByName)but with listing 2 you would have to do something like:[a, b, c].sort((left, right) => sortBy(name, left, right))