settimeout delay example js
Example 1: javascript settimeout
setTimeout(function(){
alert("Sup!");
}, 2000);//wait 2 seconds
Example 2: delay in javascript
setTimeout(function() {
//your code here
}, 1000);
Example 3: javascipt delay
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
console.log("Hello");
sleep(2000).then(() => { console.log("World!"); });