delay in javascript syncronous code example
Example 1: javascript best way to create synchronous pause in program
console.log("Start");
console.time("Promise");
await new Promise(done => setTimeout(() => done(), 5000));
console.log("End");
console.timeEnd("Promise");
Example 2: javascript synchronous wait
function delay(n) {
n = n || 2000;
return new Promise(done => {
setTimeout(() => {
done();
}, n);
});
}