3

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?

Mohammad Areeb Siddiqui
  • 9,795
  • 14
  • 71
  • 113
  • 2
    possible duplicate of ['setInterval' vs 'setTimeout'](http://stackoverflow.com/questions/2696692/setinterval-vs-settimeout) – AntouanK Jul 05 '13 at 10:55

3 Answers3

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'

Community
  • 1
  • 1
Gnanz
  • 1,833
  • 5
  • 24
  • 51
2

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)
Fabrizio Calderan
  • 120,726
  • 26
  • 164
  • 177
1

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.

AntouanK
  • 4,880
  • 1
  • 21
  • 26