title: localeCompare array with null values
body: <p>When I'm sorting my array I get the following error in console:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'localeCompare' of null
  </code></pre>
  
  <p>What I've tried so far:</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;table class="table table table-striped table-bordered table-hover" id="userLastSyncTable"&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th class="sortable sortDevicePlatform orderDevicePlatformByASC"&gt;Device Platform&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;&lt;/tbody&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>JavaScript/JQuery:</strong></p>
  
  <pre><code>var TestArray = ["iOS 7", null, "iOS 8.4", null, null, null, "iOS 9"];
  
  ShowUserSyncTable();
  
  function ShowUserSyncTable() {
      var tableRecord = '';
  
      // Loop through all the returned records and add them to select box
      for (var i = 0; i &lt; TestArray.length; i++) {
          tableRecord += "&lt;tr id=" + "" + "&gt;&lt;td&gt;" + TestArray[i] + "&lt;/td&gt;&lt;/tr&gt;";
  
      }
  
      $('#userLastSyncTable').find('tbody').html(tableRecord);
  }
  
  $(".sortDevicePlatform").click(function () {
  
      var clickedDevicePlatformSorting = $(this).hasClass('orderDevicePlatformByASC') ? 'orderDevicePlatformByDESC' : 'orderDevicePlatformByASC';
  
                  $('.sortDevicePlatform').removeClass('orderDevicePlatformByASC').removeClass('orderDevicePlatformByDESC');
              $('.sortDevicePlatform').addClass(clickedDevicePlatformSorting);
      // Sort the sync list based on device platform
      TestArray.sort(function (a, b) {
  
          if (!a) {
              // Change this values if you want to put `null` values at the end of the array
              return -1;
          }
          if (!b) {
              // Change this values if you want to put `null` values at the end of the array
              return +1;
          }
  
          if (clickedDevicePlatformSorting == 'orderDevicePlatformByASC' &amp;&amp; a) return a &amp;&amp; b ? a.localeCompare(b) : -1;
          else if (b) return a &amp;&amp; b ? b.localeCompare(a) : 1;
      });
  
      ShowUserSyncTable();
  });
  </code></pre>
  
  <p>How do I go about sorting the array with null values?</p>
  
  <p>Update Fiddle for testing:</p>
  
  <p><a href="http://jsfiddle.net/j2up76u1/2/" rel="noreferrer"><strong>FIDDLE</strong></a></p>
  
  <p><strong>Expected out come:</strong></p>
  
  <p><strong>One click show:</strong></p>
  
  <p>iOS 7, iOS 8.4, iOS 9, null, null, null, null</p>
  
  <p><strong>Another click show:</strong> </p>
  
  <p>iOS 9, iOS 8.4, iOS 7, null, null, null, null</p>