How to set a timer in JavasScript

H

How Can We Help?

How to set a timer in JavasScript

If we want to call a function every 10 seconds using JavaScript we can accomplish it by implementing the following piece of code

window.setInterval('yourfunction()', 1000);
 
function yourfunction(){
alert('test');
 
}

With the code above every 10 seconds a JavaScript function with the name yourfunction will be called that will prompt an alert.

window.setInterval = Evaluates an expression each time a certain number of seconds have elapsed

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me