Unlike the setTimeOut (functionName, delay) method which places the functionName in a queue then execute it after delay miliseconds, The following function will hold up the web page for a time period.
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
“wake up!!!” will be printed 3 seconds after “go to sleep”
console.log("go to sleep");
sleep(3000);
console.log("wake up!!!");