title: Why does points.sort(function(a, b){return a-b}); return -1, 0 or 1?
body: <p>My difficulty here could be my mathematical illiteracy, but I was trying to sort some numbers in a JavaScript array and this is the solution I found online. It does indeed work, but my question is why?! I would really like to understand this piece of code properly.</p>
  
  <p>The site, W3 Schools says:</p>
  
  <p>You can fix this by providing a function that returns -1, 0, or 1:</p>
  
  <pre><code>var points = [40, 100, 1, 5, 25, 10];
  
  points.sort(function(a,b){return a-b});
  </code></pre>
  
  <p>Why would only -1, 0 or 1 be returned? I have Googled, and return can return pretty much any value you want.</p>
  
  <p>Again, if this is an incredibly dumb question I apologise.</p>