setTimeout() Delayed execution
Last updated: 2026-09-09
setTimeout() Delayed execution
setTimeout runs a callback after the specified milliseconds. Returns a timer ID for clearTimeout.
| Category | Global Functions |
|---|---|
| ES version | ES1 |
📝 Syntax
setTimeout(callback, ms);
⚙️ Parameters
| callback | The function to run after the delay. |
|---|---|
| ms | Delay in milliseconds. |
Returns:A timer ID (number).
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
Zhang
💡 Tip setTimeout does not guarantee exact timing — minimum delay only.
ℹ️ info 0ms delay still queues after current sync code (macrotask).
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| setTimeout() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
QDoes setTimeout(fn, 0) run immediately?
ANo — queued as a macrotask, runs after sync code and microtasks.
QWhat does clearTimeout do?
ACancels a pending timer. Already-executed timers cannot be cancelled.
QWhat is this in setTimeout?
ADefaults to window; arrow functions inherit the outer this.