Javascript setTimeout function evaluates the expression after the time specified in milliseconds. setTimeout function of Javascript delays the execution of the function or expression specified with the time specified.
Javascript setTimeout syntax
setTimeout(expression, msec, lang);
setTimeout function takes 3 parameters
Expression: Name of the function to call or the javascript expression to evaluate.
Msec: Time in milliseconds after which the specified expression is evaluated.
Lang: Optional parameter to specify the scripting language e.g.: Jscript, Javascript, vbscript.
Javascript setTimeout Example
function getMessage()
{
var timeOut = setTimeout ( "alert( 'Delay of 5 seconds!!!' )" , 5000);
}
In the above example setTimeout function will display the alert message box after 5000 milliseconds i.e. 5 seconds.
Continue to next tutorial: JavaScript clearTimeout to learn how to stop the timer event.