title: can someone explain how javascript sort method works?
body: <p>I have encountered this javascript code involving a <code>sort</code> method with a custom return.</p>
  
  <pre><code>const nums =  ['9', '5', '3', '34', '30' ];
  const num = nums.map(n =&gt; n.toString()).sort((a,b) =&gt; a + b &lt; b + a? 1: -1).join('')
  </code></pre>
  
  <p>Essentially, this code is returning the largest possible integer.  I have the basic knowledge of sort, if you want the numbers in ascending order then you'll use <code>a-b</code> for the return.  If descending is desired, then you would use <code>b-a</code>. </p>
  
  <p>I want to know how the <code>a</code> and <code>b</code> are working behind the scenes.  I couldn't find a source where it explains in details how the sort works. I would like to know step by step when the <code>sort</code> is in action; it will give me a better a idea how the code above works.</p>
  
  <p>Your help will be appreciated.</p>