- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript setTimeout
JavaScript Asynchronous
JavaScript setTimeout
setTimeoutruns a function once after a delay.
The delay is in milliseconds, so 1000 is one second.
It returns an id you can use to cancel it.
Example
Example
javascript
setTimeout(function () {
console.log("done");
}, 10);The message appears after ten milliseconds.
What is setTimeout?
setTimeout schedules a function to run once, later.
The delay is a minimum, not a promise - the function runs when the thread is free.
clearTimeout cancels it before it fires.
