called timing events.
Note: The setTimeout() and clearTimeout() are both methods of the HTML DOM Window object.
The setTimeout() method returns a value. In the syntax defined above, the value is stored in a
variable called t. If you want to cancel the setTimeout() function, you can refer to it using
the variable name.
The first parameter of setTimeout() can be a string of executable code, or a call to a
The second parameter indicates how many milliseconds from now you want to execute the first
Note: There are 1000 milliseconds in one second.
When the button is clicked in the example below, an alert box will be displayed after 3
To get a timer to work in an infinite loop, we must write a function that calls itself.
In the example below, when a button is clicked, the input field will start to count (for ever),
starting at 0.
Note: we also have a function that checks if the timer is already running, to avoid creating
additional timers, if the button is pressed more than once:
The example below is the same as the "Infinite Loop" example above. The only difference
is that we have now added a "Stop Count!" button that stops the timer:
Your Query was successfully sent!