Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between javascript timeout and timer methods

Tags:

javascript

JS support timeout and timer. Here is their definition:

timeout - repeat execution of a code within specific time and it returns an integer that can be used to cancel pending timeout.

var timeout_id = setTimeout(f,500);
cleartTimeout(timeout_id);

timer - repeat exectuion of code at specific interval.

id = setInterval(F,5000);
clearInterval(id)

I am a little confused, what is their difference?

like image 437
SecureFish Avatar asked Apr 24 '26 13:04

SecureFish


1 Answers

setTimeout executes the code only once.

setInterval executes the code at every xxx amount of time.

like image 129
Jose Faeti Avatar answered Apr 26 '26 04:04

Jose Faeti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!