pause javascript code code example
Example 1: how to wait in javascript
function pause(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
pause(1000)
Example 2: wait javascript
wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Example 3: javascript sleep function
sleep = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));
sayHi = async () => {
await sleep(1000);
console.log('Hi');
}
Example 4: pause javascript
function wait(ms)
{
var d = new Date();
var d2 = null;
do { d2 = new Date(); }
while(d2-d < ms);
}