title: Why Javascript Array.sort function doesnt throw an error when incorrect compare function
body: <p>Why Javascript <code>Array.sort</code> function doesnt throw an error when incorrect compare function (i.e. function with number of parameter != 2) is passed to it for sorting. As per my understanding the sort function has optional compareFunction function. This function expects 2 parameter. </p>
  
  <p>Example1: compareFunction with 1 parameter</p>
  
  <pre><code>var ar = [1,4,2,3];
  console.log(ar.sort(function(a){return 2-a;}));
  </code></pre>
  
  <p>Output on console</p>
  
  <pre><code>VM239:2 [4, 2, 3, 1]
  </code></pre>
  
  <p>Example2: compareFunction with 2 parameter</p>
  
  <pre><code>var ar = [1,4,2,3];
  console.log(ar.sort(function(a,b,c){return a-b-c;}));
  </code></pre>
  
  <p>Output on console</p>
  
  <pre><code>VM408:2 [1, 4, 2, 3]
  </code></pre>