

The setTimeout() method returns the interval id.

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')
