Here's another example, this one containing two timers. The first one is set to close the window after 30 seconds. However, 10 seconds in, the second one will activate and ask the user to confirm the timeout. If the user does not confirm it, the timeout will be cancelled.
Note that after the confirm() dialog bog is displayed and while it is waiting for a user click, all timers are suspended.
Here's another example, this one using the setTimeout() method to create a countdown clock. Take a look:
In this case, I'm using the setTimeout() method to call itself in a loop every second, and updating the value of the countdown clock on every iteration of the loop. When the countdown hits 0, an alert box is displayed.