javascript delay some seconds 1

javascript delay some seconds

let ms = 50; // This is the amount of ms you want your code to wait!
let start = new Date().getTime();
let end = start;
while(end < start + ms) {
  end = new Date().getTime();
}

Here is what the above code is Doing:
1. We create a variable called start and set it equal to the current time in milliseconds.
2. We create a variable called end and set it equal to the current time in milliseconds.
3. We create a while loop that will run until the current time in milliseconds is equal to the start time plus the amount of milliseconds we want to wait.
4. Inside the while loop, we update the end variable with the current time in milliseconds.
5. Once the while loop is done, we have waited the desired amount of time.

Similar Posts