![]() |
VOOZH | about |
The setTimeout() method in JavaScript is used to execute a function or a piece of code after a specified time delay. It is commonly used for scheduling one-time tasks such as delayed actions, animations, or notifications.
Syntax
setTimeout(function, delay, arg1, arg2, ...);Where,
Example:
Output: After 2 seconds,
Hello, world!The setTimeout() function is utilized to introduce a delay or to execute a particular function after a specified amount of time has passed. It is part of the Web APIs provided by browsers and Node.js, allowing asynchronous execution of code.
setTimeout() takes a callback function and a delay in milliseconds."Start" and "End" are logged before the delayed function executes.setTimeout().JavaScript provides a corresponding function called clearTimeout() to cancel a scheduled timeout before it gets executed.
Example: