xxxxxxxxxx
// Run anonymous function after 5,000 milliseconds (5 seconds)
setTimeout(() => {
// Run code
}, 5000);
xxxxxxxxxx
setTimeout(() => console.log('running') , 1000)
// or
setTimeout(() => {
console.log('running')
}, 1000);
xxxxxxxxxx
setTimeout(function(){
console.log("hello");
}, 3000); //wait for atleast 3 seconds before console logging
xxxxxxxxxx
setTimeout(function(){
//code goes here
}, 2000); //Time before execution, 1000= 1 sec
or you can use the arrow function too
setTimeout(() => {
// Code to be executed after the delay
console.log('Timeout completed!');
}, 1000);
xxxxxxxxxx
console.log('hello');
setTimeout(() => {
console.log('async message that appears on the screen in 1 second')
}, 1000);
console.log('world');
// hello
// world
// async message that appears on the screen in 1 second