The setTimeout() and setInterval() are two methods you can use to schedule tasks in JavaScript. This tutorial will show you how to do it. It will introduce you both methods. It will show you how these methods work. It will also show you how to use them to schedule execution of your code.

A quick introduction

Usually, you want to execute your code as you write it. That said, there will be situations when you will want to delay the execution. Or, you may want to repeat the execution in specific intervals. JavaScript provides two methods, one for each of these goals. The setTimeout() to delay execution and setInterval() to repeat it.

There is one interesting thing about these two methods to schedule tasks. None of them is a part of JavaScript language specification. These methods are actually part of HTML Living Standard specification, defined as “timers”. Fortunately, they are supported in all browsers, even in Node.js. So, we can use them safely. Let’s take a look at them.

#javascript #settimeout #setinterval

setTimeout, setInterval and How to Schedule Tasks in JavaScript
1.25 GEEK