JavaScript – setTimeout vs. setInterval

If you need to delay execution (like sleep function), use setTimeout. If you need to repeatedly do something (like refresh stats), use setInterval.

  • window.setTimeout(“show();”,2000); // wait 2 seconds then run show()
  • window.setInterval(“show();”,3000); // run show() every 3 seconds

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *