gerwatcher.blogg.se

Sleep javascript example
Sleep javascript example









sleep javascript example

The setTimeout() method returns the interval id.

sleep javascript example

For example, showing a message to a user after the specified time. Note: The setTimeout() method is useful when you want to execute a block of once after some time. Hence, the program displays the text Hello world only once after 3 seconds. In the above program, the setTimeout() method calls the greet() function after 3000 milliseconds ( 3 second). Output This message is shown first Hello world The setTimeout() method returns an intervalID, which is a positive integer.Įxample 1: Display a Text Once After 3 Second // program to display a text using setTimeout methodĬonsole.log('This message is shown first')

  • milliseconds - the time after which the function is executed.
  • function - a function containing a block of code.
  • The commonly used syntax of JavaScript setTimeout is: setTimeout(function, milliseconds) The setTimeout() method executes a block of code after the specified time.











    Sleep javascript example