title: JavaScript numeric compare function - comparison vs subtraction
body: <p>There is the possibility of integer overflow when you try to compare numbers using subtraction in Java. See <a href="https://stackoverflow.com/questions/2728793/java-integer-compareto-why-use-comparison-vs-subtraction">Q: Java Integer compareTo() - why use comparison vs. subtraction?</a></p>
  
  <p>But, unlike Java, <a href="https://stackoverflow.com/questions/19054891/does-javascript-handle-integer-overflow-and-underflow-if-yes-how">JavaScript handles overflows and underflows</a>.</p>
  
  <p>The question is Does the following implementation of <code>compareNumeric()</code> work correctly in JavaScript?</p>
  
  <pre><code>// compareNumeric() one-liner
  function compareNumeric(a, b) {
      return a - b;
  }
  </code></pre>
  
  <p><strong>EDIT.</strong> The <code>compareNumeric</code> function should return</p>
  
  <ul>
  <li>negative value when a &lt; b;</li>
  <li>0 when a = b;</li>
  <li>positive value when a > b.</li>
  </ul>
  
  <p><code>a</code> and <code>b</code> are Numbers.</p>