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:
This can also be used with anonymous function:setTimeout(myFunction, 2000);
function myFunction() {
console.log("End of delay!");
}
setTimeout( () => { console.log("End of delay!"); }, 2000);
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:
This can also be used with anonymous function:setTimeout(myFunction, 2000);
function myFunction() {
console.log("End of delay!");
}
setTimeout( () => { console.log("End of delay!"); }, 2000);
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:
This can also be used with anonymous function:setTimeout(myFunction, 2000);
function myFunction() {
console.log("End of delay!");
}
setTimeout( () => { console.log("End of delay!"); }, 2000);
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:
This can also be used with anonymous function:setTimeout(myFunction, 2000);
function myFunction() {
console.log("End of delay!");
}
setTimeout( () => { console.log("End of delay!"); }, 2000);
# | ID | Query | URL | Count |
---|