View Full Version : setTimeout

08-05-2008, 11:38 PM
In a javascript, assume there are three sequencial lines:

var a = "1st line";

setTimeout("2ndLine()", 1000);

var b ="3rd line"


function 2ndLine(){


Obviously, the order of the execution is:

var a = "1st line";

then, setTimeout("2ndLine()", 1000);

Now once it hits this line, will it call the setTimeout function and wait for 1000ms, then execute the function 2ndLine(), then finally the var b ="3rd line"? OR

it call the setTimeout function, put the 2ndLine() on hold (for 1000ms), but at the mean time, go ahead execute the 3rd line, i.e., var b ="3rd line" (so in this case, it is possible for the execution of 2ndLine() to happen after the 3rd line)?



08-06-2008, 12:24 AM
It will put secondline(); on hold but continue to run the rest of your script, so yes if you code it like this secondline() will execute after the third line or however many other lines that it can process in that second

08-06-2008, 02:28 PM
A simple test would tell you what happens



08-06-2008, 03:03 PM
setTimeout() is not a break, nor a return. It is a simple bomb clock. While the chronometer ticks, life goes on and the rest of the code lines keep running till the Boom!... :)

08-06-2008, 09:01 PM
Variable names cannot start with numbers.

08-06-2008, 10:01 PM
@Trinithis you're completely right. My mistake

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum