Skip to main content

setTimeout()

setTimeout() executes a piece of code once after a specified amount of time has passed.

Signature

setTimeout(callbackFunction: Function, delay: number)

Parameters

callbackFunction

A function you want to call once a delay timer (in milliseconds) has passed.

delay

The time in milliseconds to wait before calling the callbackFunction.

Example: You can use the showAlert() function to show an alert message when delay time has passed as shown below:

setTimeout(() => { showAlert("5 seconds have passed") }, 5000);

See also

setInterval()
clearInterval()