how to delay in javascript | SoloLearn: Learn to code for FREE!


how to delay in javascript

5/2/2019 7:41:58 AM

@bdul rahman;

6 Answers

New Answer


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"


Can you give easy example


Use the setTimeout() function


<h1>You can use the function settimeout() to do it 1 time and setInterval() to do it continuously</h1>