Hi! I’m new to JS but I know some about recursion. I ran into this recursive code to display time, that works and runs well but I have some doubts.
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
setTimeout(startTime, 500);
console.log(h + “:” + m + “:” + s);
}
What confuses me is that the code runs into the recursion line (the timeout), then continues running (because it actually posts the time into the log), and then the new call to the function kicks in (after 500 miliseconds)
What confuses me is that the code continues running without completing the recursion line.
Could you explain me what happens? Is it that there is something special about the setTimeout function?