How to cancel an interval with clearInterval()
mainWhen you call setInterval(), it returns a non-zero numeric intervalID. To cancel the recurring execution, pass this ID to clearInterval().
While setInterval() and setTimeout() share the same pool of IDs—meaning clearInterval() and clearTimeout() can technically be used interchangeably—it is best practice to match them correctly (setInterval with clearInterval) to maintain code clarity.