Home > Article > Web Front-end > JavaScript scheduled function call
setTimeout("test()",1000): Execute once after a given time
setInterval("test()",1000): Execute once after a given time
The time unit is milliseconds
setTimeout can also be used to implement Repeatedly execute after a fixed period of time:
function test(){
//Your logic processing
setTimeout("test()",1000);
}
The difference between these two methods is:
setTimeout must be executed Your logic will be executed after a fixed time. It is a single process and will not affect the public data.
setInterval is executed once every fixed time, regardless of whether the previous method has been completed. It is a multi-process. There may be errors when modifying shared data