setTimeout()

Schedules a function to run once after a delay in milliseconds.

Since ES1 Spec ↗

Syntax

setTimeout(callback, delay, ...args)

Returns

number — A timer id that can be passed to `clearTimeout()`.

Examples

setTimeout(() => console.log("later"), 0);
console.log("now");
Output
now
later
setTimeout((a, b) => console.log(a + b), 0, 2, 3);
Output
5

Notes

- The delay is a minimum, not a guarantee; the callback runs after the current task and any earlier-due timers. - Nested timeouts are clamped to a minimum (about 4ms) after several levels in browsers. - In Node.js it returns a `Timeout` object, not a plain number.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also