set interval in Typescript
The set interval function is important role to execute the program in certain interval of time. Whatever code is written in setInterval function that execute at a fixed time. The time range is started from millisecond.
Syntax :
setInterval( callback , time)
callback:- ()=>
time:- We take time in millisecond E.g(2000)
The example is given below that execute the code on every 2 seconds (2000ms)
setInterval(()=>{
console.log("Hello world")
//2000 is millisecond it means this program print hello world every 2 second
} , 2000)
Try other set interval code with a function call
setInterval(()=>{
//call other function whatever you want to execute
intervalcall()
} , 2000)
function intervalcall(){
console.log("Hello Fellow user")
}
Try other set interval code with a time to start trigger
setInterval(()=>{
if(new Date().getSeconds() == 20){
//In case date in minute you use "new Date().getMinutes"
//In case date in hours you use "new Date().getHours()"
console.log("Hello Fellow users, trigger on 20 seconds")
}
}, 1000)
Comments
Post a Comment