forked from Swap76/Learn-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimerFunctions.js
More file actions
27 lines (20 loc) · 828 Bytes
/
Copy pathtimerFunctions.js
File metadata and controls
27 lines (20 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// setTimeout setInterval in both functions the time is specified in millisecond
// setTimeout This runs a code after given time starting form calling this method in program.
setTimeout(() => {
console.log("SetTimeout is Called");
}, 5000); // This will print SetTimeout is Called after 5sec after calling it
// For stopping this we can use ClearTimeout
// setInterval This runs a code after specific interval of time till we stop the timer.
starting = setInterval(() => {
console.log("SetInterval is Called");
}, 3000); // This will print setInterval is Called after every 3sec
// We can stop the interval and timeout using clearTimeout and clearInterval
setTimeout(() => {
clearInterval(starting);
}, 7000);
// Output of this whole program is
/*
SetInterval is Called
SetTimeout is Called
SetInterval is Called
*/