1.setTimeout() //executes the code after x seconds.
2.setInterval() //executes the code **every** x seconds.
1var intervalID = setInterval(alert, 1000); // Will alert every second.
2// clearInterval(intervalID); // Will clear the timer.
3
4setTimeout(alert, 1000); // Will alert once, after a second.
5setInterval(function(){
6 console.log("Oooo Yeaaa!");
7}, 2000);//run this thang every 2 seconds
1/*The difference between setTimeout() and setInterval() is that
2setTimeout() only executes code once, but setInterval() executes
3the code each amount of time you input. For example,*/
4
5/*In this function, it executes a function after 1000 milliseconds, or 1
6second.*/
7function oneSecond(){
8 setTimeout(1000, function(){
9 console.log('That was 1 second.')
10 })
11}
12
13/*In this function, it executes a function every 1 second*/
14function stopWatch(){
15 var count = 0;
16 setInterval(1000, function(){
17 console.log(count + " Seconds passed")
18 })
19}
1var intervalID = setInterval(alert, 1000); // Will alert every second.
2// clearInterval(intervalID); // Will clear the timer.
3
4setTimeout(alert, 1000); // Will alert once, after a second.
1var intervalID = scope.setInterval(func, [delay, arg1, arg2, ...]);
2var intervalID = scope.setInterval(function[, delay]);
3var intervalID = scope.setInterval(code, [delay]);
4