i want to make a review within my code, i am making a JavaScript/ajax code that will run every sec. Now here is what my code does,
It will check if there are changes in the queue, if there is changes, then it will alert, if there were no changes, then it will continue running to always check, now why is it sometimes it will alert and sometimes it will not alert. Here is my code: 

```
function check_getqueue(clinicID, userID) {
var tmpCountQ = [];
  $.ajax({
    url: siteurl+"sec_myclinic/checkingUpdates/"+clinicID+"/"+userID,
    type: "POST",
    dataType: "JSON",
    success: function(data) {
      for(var i=0;i<data.length;i++) {
        tmpCountQ.push(data[i]['queue_id']);
      };
      if(typeof lastCon[0] != "undefined")
      {
        for(j=0;j < tmpCountQ.length;j++)
        {
          if(tmpCountQ[j] != lastCon[j])
          {
            $("#boxqueue").empty();
            alert("there is change");
            // refresh_afterdel(clinicID, userID);
            lastCon[j] = tmpCountQ[j];
          } 
        } 
      }
      else
      {
       lastCon = tmpCountQ;
      }
      // console.log("lastCon "+lastCon)
      // console.log("tmpCountQ "+tmpCountQ);
    }
  });
}

```