a - b returns the difference, but the specific amount doesn’t matter, only whether that value is positive, negative, or zero.
If a - b returns a negative value, then it logically means that a is a smaller number than b, so their order remains unchanged [smaller value should come first].
If a - b returns a positive value, then it logically means that a is a larger number than b, so their order is switched [larger value should come second].
If a - b returns zero, then they are left alone, as it doesn’t matter which one comes first.
The sort() function iterates over all the indexes of the array, two items at a time, and switches their order by using the returned value [positive, negative, or zero] to determine whether a or b is the larger value. It switches them only if a - b returns a positive value.