How to delay a JavaScript function call using JavaScript?
Answers
Answer -
Hi. In order to delay a function, you can use the JavaScript method known as "setTimeout()"
This method accepts 2 parameters, ie, a function and the time in Milliseconds, which is basically an integer.
In order to delay your function just use -
setTimeout(yourFunction, time);
Example -
Suppose you have a function named myFunction -
function myFunction()
{
return 1+1;
}
In order to delay the function -
setTimeout(myFunction, 3000 ); // delaying the function by 3 seconds.
Answer:
Hi. In order to delay a function, you can use the JavaScript method known as "setTimeout()"
This method accepts 2 parameters, ie, a function and the time in Milliseconds, which is basically an integer.
In order to delay your function just use -
setTimeout(yourFunction, time);
Example -
Suppose you have a function named myFunction -
function myFunction()
{
return 1+1;
}
In order to delay the function -
setTimeout(myFunction, 3000 ); // delaying the function by 3 seconds.