You are here: irt.org | FAQ | JavaScript | Timeout | Q1272 [ previous next ]
The setTimeout method takes an expression to be evaluted after the interval has expired. The expression is commonly used by way of a string - but it doesn't have to be - it can be anything that evaluates to some string that can then be passed to the setTimeout method.
So if we use:
setTimeout(functionA(parms),7000); //--></script>
It executes functionB() now! Passing the parms to functionB() now! And then passes its result as input to the setTimeout method which is then evaluted in 7 seconds time.
Note: if the functionA() returns nothing then the JavaScript code will throw an error.
If using:
setTimeout('functionA(parms)',7000); //--></script>
We pass a string 'funtionB(parms)' as input to the setTimeout method which is evaluated in 7 seconds time. If parms no longer have scope within this context, or functionA() no longer exists then an error occurs.