So it runs through and applies whatever algorithm it wants to sort the values in your array. All it needs to know is how to tell which one is "bigger" or which one should be forward indexed.
I guess it helps to have some more familiarity with how javascript works. With javascript you can assign variables as functions and as such you can pass functions as parameters. It comes in handy in situations like this and for asynchronous callbacks (if you've played with jquery you've likely seen this in ajax calls and they're called for after various transformations are completed...like if you want one element to move 500px and then as soon as it completes it you move it down 500px, you put the down move function in the call back).
long story short, the a and b values come from your array, which values it pulls out are up to the sort function.
the awesome thing about the comparison function of sort is say you have an object that looks like this:
sales:[{sale:{"brand":"Nike", "person":"Eric", "total":5000}}, {sale:{...}}]
you can do use a sorting function to sort by brand then total like this:
sales.sort(function(a,b){
if (a.brand==b.brand){
return a.brand>b.brand ? 1 : -1;
} else {
return a.total-b.total;
});
I tend to think stuff like that is really neat...it lets the language use the most efficient sorting algorithm it feels like using and all you have to do is show it how to determine if one is "bigger" than another.