Skip to main content

Explain setTimeout vs setInterval.

Entry JavaScript
Quick Answer setTimeout(fn, ms): calls fn once after ms milliseconds. setInterval(fn, ms): calls fn repeatedly every ms milliseconds. Both are async รขโ‚ฌโ€ they don't block. The actual delay may be longer than specified (minimum is 0ms, actual depends on event loop state). Always clearInterval(id) to stop a repeating interval, or it runs forever.

Answer

setTimeout: runs code once after delay.

setInterval: runs repeatedly at intervals.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice