Why does !== work in my facotrchain function, but not === in Javascript

Why is it that the following code works when I use !== in the conditional statement, but when I change it to === as in the second section of code, it does not work.

1.

function factorChain(arr) {
    //iterate through array
  for(var i = 0; i < arr.length; i++){
    if(arr[i+1] % arr[i] !== 0){
     return false;
    } 
  }
  //check to see if previous element is a factor of current element
  //if so, return true
   return true;
}
function factorChain(arr) {
    //iterate through array
  for(var i = 0; i < arr.length; i++){
    if(arr[i+1] % arr[i] === 0){
      return true;
    } 
  }
  //check to see if previous element is a factor of current element
  //if so, return true
  return false;
}


console.log(factorChain([2, 4, 6, 7, 12]));

Source: Ask Javascript Questions

LEAVE A COMMENT