☰
👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.
How to create a simple delay in JavaScript?

The standard way to create a delay in JavaScript is to use the setTimeout(callback, ms) method. The first parameter is the callback function, the second one is the duration in milliseconds:

setTimeout(myFunction, 2000);

function myFunction() {
	console.log("End of delay!");
}
This can also be used with anonymous function:

setTimeout( () => { console.log("End of delay!"); }, 2000);

More