JavaScript pause for 1 second | log, function and Recursively Examples

JavaScript doesn’t have a sleep function that will delay a program’s execution for a given number of seconds. However, you can create a delay in JavaScript is to use its setTimeout method.

A setTimeout will pause a 1-second function or code in JavaScript pause for 1 second.

1000 MS = 1 SEC

JavaScript pause for 1 second Example code

Let’s see HTML example code of to print log “Hello” to the console, then after one seconds “World!”

Output:

JavaScript pause for 1 second example

JS Sleep Function with 1 second delay

Let’s set time delay in JavaScript function.

Recursively call a method

A program for recursively call a method that performs the check every second using setTimeout:

Do comment if you have any doubts and 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.