In this post, we will learn about How do I set up setInterval(), clearInterval(), setTimeout() with an example.
The setTimeout() function in general can be compared used to a countdown timer.
It’s a setTimeout(expression, timeout); runs to the code and function once after specific the timeout.
the setTimeout will be executes the function only once on a time out.
It’s specific used to execute a certain setTimeout function at the end of given time.
Syntax: setTimeout(function/code,(1000)Time in milliseconds);
Example of setTimeout() function
the setInterval(your expression, timeout(1000)); It’s runs the codeor function in some intervals, with the specific length of the your timeout between them.
The setInterval executes main the function continuously repeatedly on and some interval in milliseconds.
A setInterval() in generally can be compared to an alarm clock that strikes given after a particular time display, It repeats data value it self at regular time format that is passed to this function.
Syntax: The setInterval(code/Function,(1000)Time in milliseconds);
Example of setInterval() function
Example of setInterval and setTimeout function
var intervalID = setInterval(alert, 1000); // here It Will alert every second display. // clearInterval(intervalID); //here it Will clear the timer specific. setTimeout(alert, 1000); // it Will alert only once,and after a second.
setInterval and how to use clearInterval
var handle = setInterval(drawAll, 20); // When you sometimes want to cancel it: clearInterval(handle); handle = 0; //handle the setInterval
We hope you get an idea about
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.
We hope This Post can help you…….Good Luck!.