setInterval continue running after return statement

a simple function has a setInterval function internally why setInterval continue running even after function has complete return statement

function test(){
  setInterval(()=>{
    console.log(1)
  },1000)

  console.log('end')
  return 0;
}


test() //output: end 1 1 1 1 1 1

Answer

setInterval(function, t ) is a webapi for calling a callback function after every t milliseconds. So that’s the reason why it’s running continuously.