javascript settimeout syntax code example

Example 1: javascript settimeout

setTimeout(function(){
 	alert("Sup!"); 
}, 2000);//wait 2 seconds

Example 2: javascript set delay

var delayInMilliseconds = 1000; //1 second

setTimeout(function() {
  //your code to be executed after 1 second
}, delayInMilliseconds);

Example 3: set timeout javascript

setTimeout( () => {
 	alert("J'aime les chats"); 
}, 2000);//wait 2 seconds

Example 4: javascript setinterval

setInterval(function(){ 
	console.log("print this once every 3 second");
}, 3000);//run this thang every 3 seconds

Example 5: javascript settimeout

var timeoutID;

function delayedAlert() {
  timeoutID = window.setTimeout(window.alert, 2*1000, 'That was really slow!');
}

function clearAlert() {
  window.clearTimeout(timeoutID);
}