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)
Try other set interval code with a function call
setInterval(()=>{
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){
console.log("Hello Fellow users, trigger on 20 seconds")
}
}, 1000)
Comments
Post a Comment