What is the use of setTimeout() in JavaScript?
Emily Wilson
Updated on March 18, 2026
What is the use of setTimeout() in JavaScript?
The setTimeout () is a method of the window object. The setTimeout () sets a timer and executes a callback function after the timer expires. The following illustrates the syntax of setTimeout (): let timeoutID = setTimeout (cb delay], arg1, arg2,…); In this syntax: cb is a callback function to be executed after the timer expires.
How to highlight current/active menu using jQuery or JavaScript?
Highlight Current/Active Menu Using JQuery or Javascript 1 JQuery. Using JQuery is a more elegant solution and requires far less code than the JavaScript equivalent. Open the HTML… 2 JavaScript. 3 CSS. Now we need to add some custom CSS to style the menu. You do this from “Template” -> “Customise” -> “Advanced” ->… More
What is the default delay for setTimeout() method?
If you omit it, the delay defaults to 0. arg1, arg2, … are arguments passed to the cb callback function. The setTimeout () returns a timeoutID which is a positive integer identifying the timer created as a result of calling the method.
How does setTimeout work with event loop?
The setTimeout () executes and creates a timer in the Web APIs component of the web browser. When the timer expires, the callback function that was passed in the setTimeout () is placed to the callback queue. The event loop monitors both the call stack and the callback queue.
What is luakit and who is it for?
It is primarily targeted at power users, developers and anyone who wants to have fine-grained control over their web browser’s behaviour and interface. Luakit in normal mode when reading a web page. Luakit in follow mode with several link hints visible. Luakit showing the ad blocker settings page, listing currently active filter lists.
How do I install luakit on Linux?
Arch Linux users can install the luakit-git package from the AUR. Other users will need to download and build from source. A Debian package is in the works. Luakit contains only around 9000 lines of code, so this process is usually very fast. FreeBSD and OpenBSD users can install the luakit package.
How do I cancel the timeout created by setTimeout?
The setTimeout () returns a timeoutID which is a positive integer identifying the timer created as a result of calling the method. The timeoutID can be used to cancel timeout by passing it to the clearTimeout () method. The following creates two simple buttons and hooks them to the setTimeout () and clearTimeout ().