JavaScript delay function | Simple example code

The window object allows the execution of code at specified time intervals. To delay a function call, you can use setTimeout() function. This function will Execute a function, after waiting for a specified number of milliseconds.

JavaScript delay function Example code

HTML example code where you have to click a button and wait 1 second and the page will alert “1 second! Alert”:

Output:

JavaScript delay function

Do comment if you have any doubts or suggestion on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.