{"id":5234,"date":"2023-06-24T19:26:16","date_gmt":"2023-06-25T00:26:16","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=5234"},"modified":"2023-08-08T23:24:40","modified_gmt":"2023-08-09T04:24:40","slug":"how-to-do-a-simple-timer-in-javascript","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/how-to-do-a-simple-timer-in-javascript\/","title":{"rendered":"How To do a simple Timer in JavaScript"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.freecodecamp.org\/news\/javascript-timers-everything-you-need-to-know-5f31eaa37162\/\">https:\/\/www.freecodecamp.org\/news\/javascript-timers-everything-you-need-to-know-5f31eaa37162\/<\/a><\/p>\n\n\n\n<p>Here are a couple different ways to do timers in JavaScript<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Every X seconds do<\/h2>\n\n\n\n<p>We can use the setInterval global function to run code (myFunc()) every second.<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code class=\"\">setInterval(() =&gt; {\n  myfunc()\n}, 1000)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Execute X after Y seconds<\/h2>\n\n\n\n<p>Replace console.log with the code you want to execute with a delay.<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code class=\"\">setTimeout(() =&gt; {   \n  console.log(\"Hello World\")\n}, 1000)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.freecodecamp.org\/news\/javascript-timers-everything-you-need-to-know-5f31eaa37162\/ Here are a couple different ways to do timers in JavaScript Every X seconds do We can use the setInterval global function to run code (myFunc()) every second. Execute X after Y seconds Replace console.log with the code you &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/how-to-do-a-simple-timer-in-javascript\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1460,792],"tags":[644,1437,1463,1522],"class_list":["post-5234","post","type-post","status-publish","format-standard","hentry","category-javascript","category-programming","tag-code","tag-javascript","tag-js","tag-timers"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=5234"}],"version-history":[{"count":3,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5234\/revisions"}],"predecessor-version":[{"id":5424,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5234\/revisions\/5424"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=5234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=5234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=5234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}