setinterval or settimeout javascript code example
Example 1: difference between setTimeout() and setInterval()
.setTimeout() //executes the code after x seconds.
.setInterval() //executes the code **every** x seconds.
Example 2: js wait for time
function sleep(milliseconds) {
const start = Date.now();
while (Date.now() - start < milliseconds);
}
console.log("Hello");
sleep(2000);
console.log("World!");