Understanding code logic with the sort function

Question: The code below is the answer given to sort an array in reverse Alphabetical order. I don’t understand what the “1” and “-1” represent respectively?

function reverseAlphabeticalOrder(arr) {
  // Add your code below this line
  return arr.sort(function(a, b) {
    return a === b ? 0 : a < b ? 1 : -1;
  // Add your code above this line
reverseAlphabeticalOrder(["l", "h", "z", "b", "s"]);
// Returns ['z', 's', 'l', 'h', 'b']

the 1 and -1 are a requirement for sort.

(compareFunction is the name given to the sortcallback)

This is from the MDN page on sort:

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thanks for the reply.