This JS code when run gives an output. Shouldn't this lead to infinite recursive calls and hence show Time Limit Exceeded? Pls explain the flow of program.
function main(ctime){
window.requestAnimationFrame(main);
if(start==undefined){
start= ctime;
}
if((ctime-start)/1000<0.5){
console.log(ctime);
return;
}
}
window.requestAnimationFrame(main);
There is no recursion here. window.requestAnimationFrame(main); just puts the main in the callback queue without executing or waiting it (like setTimeout() does) and returns immediately, then the next line is executed.