setTimeout() can be used to run a function after a certain time delay.
setTimeout() method takes two parameters:
- The function that needs to be run
- The time delay in milliseconds
The example given below
Hello, World! onto
the console after a delay of 3 seconds.
If the function that you are passing to
setTimeout needs arguments, you can pass them by adding them after the first two parameters of the
setTimeout() method call as shown below:
setTimeout() method returns a number value.
This value can be used to cancel the timeout later if needed.