How does points.sort(compare) work exactly?

From Web Development 101, Fundamentals Part 4:
https://www.theodinproject.com/courses/web-development-101/lessons/fundamentals-part-4?ref=lnav

I kind of know how this works, but I have a few questions:

https://www.w3schools.com/js/js_array_sort.asp
var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a - b});
// now points[0] contains the lowest value
// and points[points.length-1] contains the highest value

points.sort is an alphabetical sort

points.sort(function(a, b){return a - b}); tells it to sort using a compare function.

The compare function is (function(a, b){return a - b})

{return a - b} tells how big or small a number is by subtracting one from the other and getting a sum. The order of those sums corresponds with each “a” that’s tested against a “b”.

How does the computer keep track of these sums and know to translate it back to the “a” in the array?

This is what I’m having a hard time wrapping my mind around. If I wanted to do something to an array repeated like the compare function does, it would be helpful to understand how this works.

Or should I just accept that a compare is that?