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
// disable button using prop.$(".button").click(function(){// disable button$(this).prop('disabled',true);// do something// below code enables button clicking after two seconds.setTimeout(()=>{// enable button$(this).prop('disabled',false);},2000);});
//setTimeout having parameater //1. function//2. time in mili second//parm1 , parm2 ........setTimeout(function(){console.log("DARK_AMMY");},2000);//wait 2 seconds
setTimeout(function(){//Insert code here. Here is an example using discord.js
message.channel.send("Waited 5 seconds before sending this message.");},5000);//Waits 5 seconds before executing the function/code.//Code by: @NickIsNotADev#3506 on Discord.
//You can also send a argument along with a timed callsetTimeout("your_fun('bob');",1000)functionyour_fun(name){//Prints "Hello world! bob" after one secondalert("Hello world! "+ name);}
functionfunc(){this.var=5;this.changeVar=function(){setTimeout(()=>{//Don't use function, use arrow function so 'this' refers to 'func' and not windowthis.var=10;},1000);}}var a =newfunc();
a.changeVar();
// setTimeout() Method in javascriptfunctionsetTimeoutFunction(){setTimeout(function(){console.log("This message will display after 5 seconds");},5000);}setTimeoutFunction();
functiondoHomeWork(subject, callback){setTimeout(callback,500);console.log("doing my homework:", subject)}doHomeWork("Maths",function(){console.log("finished my homework");});
// program that shows the delay in executionfunctiongreet(){console.log('Hello world');}functionsayName(name){console.log('Hello'+' '+ name);}// calling the functionsetTimeout(greet,2000);sayName('John');