---
title: "What is the working of timers in JavaScript?"  
description: "What is the working of timers in JavaScript?"  
author: "Rahul Roi"  
published: 2021-03-16  
canonical: https://www.mindstick.com/interview/33785/what-is-the-working-of-timers-in-javascript  
category: "javascript"  
tags: ["javascript", "scripting", "scripting language", "programming language"]  
reading_time: 2 minutes  

---

# What is the working of timers in JavaScript?

As we know, the timer is a control of JavaScript. But the timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. It is done by using the functions **setTimeout**, **setInterval**, and **clearInterval**.

When the **setTimeout(function, delay)** function is used to start a timer that calls a particular function after the mentioned delay. And, the **setInterval**(function, delay) function is used to repeatedly execute the given function in the mentioned delay and only halts when canceled. While the **clearInterval(id)** function instructs the timer to stop. And while the timers are operated within a single thread, and thus events might queue up, waiting to be executed.

## Answers

### Answer by Rahul Roi

As we know, the timer is a control of JavaScript. But the timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. It is done by using the functions **setTimeout**, **setInterval**, and **clearInterval**.

When the **setTimeout(function, delay)** function is used to start a timer that calls a particular function after the mentioned delay. And, the **setInterval**(function, delay) function is used to repeatedly execute the given function in the mentioned delay and only halts when canceled. While the **clearInterval(id)** function instructs the timer to stop. And while the timers are operated within a single thread, and thus events might queue up, waiting to be executed.


---

Original Source: https://www.mindstick.com/interview/33785/what-is-the-working-of-timers-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
