setTimeout or setInterval?

前端 未结 19 3155
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 04:59

As far as I can tell, these two pieces of javascript behave the same way:

Option A:

function myTimeoutFunction()
{
    doStuff();
           


        
19条回答
  •  抹茶落季
    2020-11-21 05:31

    In my opinion the simplest difference between setTimeout(expression,duration) and setInterval(expression,duration) is that:-

    setTimeout() will execute the expression only once in the specified duration.

    However, setInterval() will execute the specified expression again and again with each execution being delayed(time gap between two consecutive execution) by the specified duration.

提交回复
热议问题