Skip to main content

setTimeout

function setTimeout
Jump to headingsetTimeout<TArgs extends any[]>(
callback: (...args: TArgs) => void,
ms?: number,
...args: TArgs,
): Timeout

Schedules execution of a one-time callback after delay milliseconds.

The callback will likely not be invoked in precisely delay milliseconds. Node.js makes no guarantees about the exact timing of when callbacks will fire, nor of their ordering. The callback will be called as close as possible to the time specified.

When delay is larger than 2147483647 or less than 1, the delay will be set to 1. Non-integer delays are truncated to an integer.

If callback is not a function, a TypeError will be thrown.

This method has a custom variant for promises that is available using timersPromises.setTimeout().

Type Parameters Jump to heading

Jump to headingTArgs extends any[]

Parameters Jump to heading

Jump to headingcallback: (...args: TArgs) => void

The function to call when the timer elapses.

optional
Jump to headingms: number
Jump to heading<span>...args</span>: TArgs

Return Type Jump to heading

for use with clearTimeout

Jump to headingsetTimeout(
callback: (args: void) => void,
ms?: number,
): Timeout

Parameters Jump to heading

Jump to headingcallback: (args: void) => void
optional
Jump to headingms: number

Return Type Jump to heading

Back to top