Favorites

DOM Window.setTimeout() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.setTimeout()
DOM Window MethodThis method is supported by all modern browsers.
Updated 28th November 2026

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

console.log('start');
setTimeout(() => console.log('after 500ms'), 500);
setTimeout(name => console.log('hello', name), 200, 'Sam');
setTimeout(() => console.log('0ms still runs later'), 0);
console.log('end');

const sleep = ms => new Promise(r => setTimeout(r, ms));
sleep(800).then(() => console.log('slept'));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee