the difference between settimeout and setinterval method
SetTimeout () is used to set the corresponding function or code to execute after the specified time., executed at the global scope
SetTimeout (Code,time[,args ...]) code: function or JS code to be executed, time to wait, args: parameter
such as: function SayHello (name, age) { //popup message after 5 Seconds "My name Codeplayer, 18 years old this year!".
Alert ("I call" + name + ", this year" + Age + "old!");
SetTimeout (SayHello, "Codeplayer", 18);
SetInterval () is used to set the corresponding function or code to execute at a specified time , executing at the global scope
SetInterval (Code,time[,args ...]) code: function or JS code to be executed, time to wait, args: parameter
such as: function SayHello (name, age) { //every 5 seconds pops up the message "My name Codeplayer, 18 years old this year!".
Alert ("I call" + name + ", this year" + Age + "old!");
SetInterval (SayHello, "Codeplayer", 18);
The difference between setTimeout () and SetInterval ()
1. SetTimeOut (), execute once
2. SetInterval (), executes every few seconds
SetTimeout () implements the function of SetInterval (), using recursive algorithm
such as: function Test () {
Alert ("Test");
SetTimeout (test,2000);
}
SetTimeout (test,5000);
SetInterval () execution within the same time
SetTimeout () The time of first execution and subsequent execution can be different
The difference between settimeout and setinterval method