lundi 10 mai 2021

Recursion was unexpectedly in javascript [duplicate]

I was following a tutorial to make a basic game using javascript. In that tutorial he wrote

function main(ctime){
  window.requestAnimationFrame(main);
  console.log(ctime);
 }
 
 window.requestAnimationFrame(main);

I understand that from the 6th line we are calling the main function and then again calling it from itself for recursion.

Q) But since we are calling the function again in the main function why the console.log line gets executed, technically it shouldn't be executed even once, as the compiler would never reach there. But, it actually gets executed. Can someone tell me why this is happening .

Aucun commentaire:

Enregistrer un commentaire