function - javascript - setTimeout() vs setInterval() - Stack Overflow

What are the minor and major differences between setTimeout() and setInterval()?I searched the internet

What are the minor and major differences between setTimeout() and setInterval()?

I searched the internet but it made me confused! What's the difference between those?

What are the minor and major differences between setTimeout() and setInterval()?

I searched the internet but it made me confused! What's the difference between those?

Share Improve this question asked Jul 5, 2013 at 10:35 Mohammad Areeb SiddiquiMohammad Areeb Siddiqui 10.2k16 gold badges73 silver badges118 bronze badges 1
  • 2 possible duplicate of 'setInterval' vs 'setTimeout' – AntouanK Commented Jul 5, 2013 at 10:55
Add a ment  | 

3 Answers 3

Reset to default 4

The main diffrence is

setInterval fires again and again in intervals, while setTimeout only fires once.

you can get more differnces in simple words in

setTimeout or setInterval?

'setInterval' vs 'setTimeout'

tha major difference is that setTimeout will execute some code just once, after a given delay, while setInterval will execute a code always, with a delay between each call

e.g. try these on your console:

setTimeout(function() {
  console.log('Wait 3 seconds and I appear just once');
}, 3000);

and

setInterval(function() {
  console.log('Every 3 seconds I appear on your console');
}, 3000)

From Javascript timers MDN

setTimeout()

Calls a function or executes a code snippet after specified delay.

setInterval()

Calls a function or executes a code snippet repeatedly, with a fixed time delay between each call to that function.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744406696a4572668.html

相关推荐

  • function - javascript - setTimeout() vs setInterval() - Stack Overflow

    What are the minor and major differences between setTimeout() and setInterval()?I searched the internet

    6天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信