The answer to this question is too common. I copied a copy below and thanked the blogger.
Difference between setTimeout and setinterval in Rural Area Javascript
The only thing that deserves special attention is that JS is case sensitive. Do not write the function name wrong.
[SetTimeout]
SetTimeout (expression, latency)
During execution, the expression is executed once after the specified time delay after loading. Remember, the number of times is once.
The effect of the random number is displayed automatically when the setTimeout function is used:
<HTML>
<Head>
<SCRIPT>
Window. onload = sett;
Function sett ()
{
Document. Body. innerhtml = math. Random ();
SetTimeout ("sett ()", 500 );
}
</SCRIPT>
</Head>
<Body>
</Body>
</Html>
[Setinterval]
Setinterval (expression, interaction time)
It executes the expression once every specified time after loading.
The effect of the random number is displayed automatically when setinterval is used:
<HTML>
<Head>
<SCRIPT>
Function sett ()
{
Document. Body. innerhtml = math. Random ();
}
Setinterval ("sett ();", 500 );
</SCRIPT>
</Head>
<Body>
</Body>
</Html>
The two timer tools have their own advantages. When using setinterval, You need to manually stop tick trigger. The setTimeout nested in the method can be stopped based on the internal logic of the method.
In fact, the two things can be simulated with each other. The specific use depends on the needs at that time. Just as for can simulate all loops including branches, but also provides do and while.