I have this logic to loop over my value passed as argument and print them one letter per second

let sequenceI = 0;

function sequence(arr){
  document.getElementsByTagName('P')[0].innerHTML += arr[sequenceI];
  ++sequenceI;  
  setTimeout(() => sequence(arr), 150);
  if (sequenceI > arr.length) {
    document.getElementsByTagName('P')[0].innerHTML ="";
    sequenceI = 0;
  } 
}

sequence('Software Developer');

I have this logic to loop over my value passed as argument and print them one letter per second. Why does this not return undefined when the sequenceI becomes 18? But it rather starts the loop again