JavaScript clearInterval function clears the instance of timer calls of setInterval function. clearInterval stops the timer function of setInterval that calls the specified function after specified time intervals in milliseconds. 

Javascript clearInterval syntax

clearInterval( timerID );

clearInterval takes 1 parameter:

timerID: timer id of the timer instance initiated by setInterval function.

setInterval method returns the timerID of the instance initiated by it.

Example of JavaScript clearInterval with setInterval function

var interval;
  
function startInterval()
{
    interval = setInterval("startTime();",1000);
}

function startTime()
{
    document.getElementById('myTime').innerHTML = Date();   
}

function stopInterval()
{
   clearInterval(interval);
}

In the above example of javascript clearInterval and setInterval 1 variable (interval) is declared as global to access its value in any function at any time when required. interval a global variable is used to store the timerID returned by setInterval function. clearTimeout function takes this interval variable as a timerID parameter that cancels the timer set by setInterval function.

Continue to next tutorial: Javascript Clock Timer to learn how to create a JavaScript Clock timer.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.