how to delay in javascript | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 6

how to delay in javascript

2nd May 2019, 7:41 AM
Abdul rahman;
Abdul rahman; - avatar
4 Antworten
+ 3
As Satnam suggested you can use the setTimeout() function, which syntax is: setTimeout(function, delay); "function" is the function that you want to be executed after an amount of time equal to the variable "delay" (expressed in milliseconds). Here is an example: You want to print something to the console and after 3 seconds (3000 milliseconds), you want to print something else. You can do something like this: setTimeout(function(){ console.log("this will appear after") }, 5000); console.log("this will appear before"); The output will be: "this will appear before" //and after 3 seconds "this will appear after"
2nd May 2019, 1:09 PM
Alessia
Alessia - avatar
+ 4
Can you give easy example
2nd May 2019, 7:50 AM
Abdul rahman;
Abdul rahman; - avatar
+ 1
<h1>You can use the function settimeout() to do it 1 time and setInterval() to do it continuously</h1>
23rd Jun 2019, 5:27 AM
Shreyansh