I have created a function that runs after 1.8 million milliseconds (I’m using 1.8 seconds for test purposes), but the timeout I’m using never seems to work – even though it’s exactly the same one I’ve used for every other web app/site I’ve made, ever.
Core code:
setTimeout(Test, 10);
var Test = function(){
alert("KEMAH");
};
Jsfiddle: http://jsfiddle.net/zbMCC/1/
Place the timeout after the function expression.
Function expressions (functions assigned to variables) are not “hoisted-up” in the scope. Thus the code executes in the order they appear.
On the otherhand, function declarations are hoisted-up in the scope, so the following code runs perfectly. Notice how the function is declared. Its declared as a function with a name
Test, instead of having a function assigned to the variableTest:JavaScript ses your code this way: