SetTimeOut and SetInterval

Damruwan Weerasinghe
2 min readJun 7, 2021

Have you ever visited a website, which shows some kind of animation displaying how many followers they have or maybe how many subscribers they have in their YouTube channel? In this article, we are going to implement such an animation using javascript. Don’t worry this not going to require expert javascript knowledge or any other plugins. By using two, times event in javascript we are going to implement an animation that shows the number of followers in our Instagram account. Before moving to implementation, we are going to have look at these two, time events.

SetTimeOut(function, millisecond)

For this event, you have to pass the function which should perform and the time period in milliseconds. Let say you give 1500 millisecond as the time. After the program execution, before executing this SetTimeOut event, the program will wait for 1500 milliseconds and then start to execute the function inside the SetTimeOut Event.

SetInterval(function, millisecond)

SetInterval event is somewhat different than the SetTimeOut event. For this event also have to pass the function which should perform and the time period in milliseconds. Let say you give 1500 millisecond as the time. When the program executes, the function inside the SetInterval should execute within 1500 milliseconds.

Let’s try to understand these concepts using an example.

index.html
style.css
script.js

--

--

Damruwan Weerasinghe
0 Followers

Join me on my journey as I share insights, tips, and tutorials on my Software Engineering journey. Let's code, learn, and grow together