I have a question about how setTimeout works. Does it wait for the previous code to finish executing before moving on to execute something else after a set time, or does it simply wait for a specific amount of time and then continue with the rest of the code regardless of whether the previous code has finished?
if (1 == 1) {
//a lot of code
} //end of if (1 == 1)
var theTime = 1000;
var timeout = setTimeout("location.reload(true);", theTime);
function resetTimeout() {
clearTimeout(timeout);
timeout = setTimeout("location.reload(true);", theTime);
} //end of function resetTimeout()
My aim is to ensure that the first part of the code finishes executing before refreshing the page immediately after completion. Is there a way to achieve this using setTimeout?