$0.26

What is the difference between setTimeout and setInterval?

Ask a question+
1

As I understand, these two pieces of javascript code behave the same way:

First way:

function myTimeoutFunction()
{
    doStuff();
    setTimeout(myTimeoutFunction, 1000);
}

myTimeoutFunction();

Second way:

function myTimeoutFunction()
{
    doStuff();
}

myTimeoutFunction();
setInterval(myTimeoutFunction, 1000);

Is there any difference between them setTimeout and setInterval?

BabkenM 1K
add comment

1 Answer

2

setTimeout(expression, timeout);
runs the code/function once after the timeout.

setInterval(expression, timeout); 

runs the code/function in intervals, with the length of the timeout between them.

Marc Gravell 520
add comment

Your Answer