function sayHi(phrase, who) {
  alert( phrase + ', ' + who );
}

let timerId1 = setTimeout(sayHi, 1000, "Hello", "John"); // Hello, John
let timerId2 = setTimeout(() => alert('Hello'), 1000);

clearTimeout(timerId1);
clearTimeout(timerId2);
// repeat with the interval of 2 seconds
let timerId = setInterval(() => alert('tick'), 2000);

// after 5 seconds stop
setTimeout(() => { 
	clearInterval(timerId); 
	alert('stop'); 
}, 5000);

Recursive setTimeout

let delay = 5000;

let serverRequest = () => {
	// Send request...
	if (requestFailed) {
		setTimeout(serverRequest, delay);
	}
}

setTimeout(…,0)

Debouncing

const inputEle = document.getElementById("inputElement");
const username = document.getElementById("username");

const generateUsername = (e) => username.innerHTML = e.target.value.split(" ").join("-");

const debounce = (callback, delay) => {
  let timer;
  return function () {
    const context = this;
    timer && clearTimeout(timer);
    timer = setTimeout(() => callback.apply(context, arguments), delay);
  }
}

inputEle.addEventListener("keyup", debounce(generateUsername, 300));