DOM Window.setTimeout() Method
The setTimeout() method runs a function once, after a delay in milliseconds.
Description
The setTimeout() method schedules a function to run once after the given delay. It returns straight away with an ID you can pass to clearTimeout() to cancel it. The delay is a minimum: the callback runs when the browser is next free after the time has passed, and nested timers and inactive tabs can be delayed further.
A delay of 0 still runs the callback later, after the current code finishes. Wrapping it in a promise gives a simple await-able pause. Passing a string instead of a function is possible but should be avoided, like eval().
The this value inside a regular function callback is the global object, which can cause surprises with methods; use an arrow function or bind() to keep the right this. The maximum delay is about 24.8 days; larger values overflow and run immediately.
Syntax
setTimeout(callback)
setTimeout(callback, delay)
setTimeout(callback, delay, arg1, arg2, ...)Parameters
- callbackThe function to run when the timer expires.
- delayOptional. The time to wait, in milliseconds. Defaults to 0.
- arg1, arg2, ...Optional. Arguments passed to the callback.
Return Value
A positive integer timer ID, which can be passed to clearTimeout().
Example
Browser Support
The following information will show you the current browser support for the Window.setTimeout() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





