How to set time delay in javascript

Created by HIRA THAKURLinked to 39.3m issues across 137 teams


To set a time delay in JavaScript, you can use the setTimeout() function. This function takes two parameters: a callback function and a delay in milliseconds.

For example, to delay the execution of a function by one second, you would write the following code:

var delayInMilliseconds = 1000; //1 second setTimeout(function() { //your code to be executed after 1 second }, delayInMilliseconds);