window.setTimeout() sets a timer that runs a function once after the delay expires (MDN). It returns a timeout ID — pass that ID to clearTimeout() to cancel. For repeating calls, use setInterval().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call window.setTimeout. Start with this line.
JavaScript
setTimeout(fn, delay, ...args)
Call
What it does
setTimeout(fn, delay, ...args)
Primary signature.
window.setTimeout(...)
Call with the arguments your case needs.
Built into the browser. Call window.setTimeout(...) (or the global setTimeout(...)) — no import required.
Library declarations
JavaScript
setTimeout(fn, delay, ...args)
Parameters
Parameter
Description
func
Required. Function to run once after the delay
delay
Optional. Milliseconds to wait (default 0)
param1…N
Optional. Forwarded to func when it runs
Return Value
Return Value
Description
*
Pass to clearTimeout()
JavaScript Examples
Example 1 — Run Once After a Delay
MDN: schedule a callback that runs once when the timer expires.
JavaScript
const id = setTimeout(function () {
console.log("Hello after 2 seconds");
}, 2000);
// optional: clearTimeout(id);
Recursive tip. Chain setTimeout after work finishes if the delay must wait on completion.
Compatibility
Browser Support
Window.setTimeout() is marked Baseline Widely available on MDN (since July 2015). It is not Deprecated, Experimental, or Non-standard. Available in browsers and workers; prefer function callbacks over string code.
✓ Baseline · Widely available
setTimeout()
Run a callback once after a delay across modern browsers.
99%Core tag support
ChromeYes
Full support
EdgeYes
Full support
FirefoxYes
Full support
SafariYes
Full support
OperaYes
Full support
HTML element100% supported
Bottom line: Universal timer API. Store the ID to cancel; avoid string code; remember delays can be longer under load.
Frequently Asked Questions
It sets a timer that executes a function (or code) once after the delay expires (MDN). It returns a timeout ID immediately so you can cancel with clearTimeout() before the callback runs.
No. MDN marks Window.setTimeout() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. Passing a string as code is strongly discouraged (injection / XSS risk).
A positive integer timeout ID. Pass that ID to clearTimeout() to cancel before the timer fires.
No. setTimeout is asynchronous — it schedules the callback and returns right away. Lines after the call run immediately while the timer counts down.
setTimeout runs once after a delay. setInterval repeats until cleared. Use setTimeout for one-shot delays; use setInterval (or recursive setTimeout) for repeating work.
Yes. Extra arguments after the delay are forwarded: setTimeout(greet, 2000, "Alex"). Or wrap the call: setTimeout(() => greet("Alex"), 2000).