0

I see below countdown function not work, but I do not know the execution order of this countdown. What is the execution order of this countdown function?

 function countdown() {
     let i;
     console.log("Countdown:");
     for(i=5; i>=0; i--) {
         setTimeout(function() {
             console.log(i===0 ? "Finish!" : i);
           }, (5-i)*1000)
         ;
     }
 }
 countdown();
kinjia
  • 41
  • 5
  • 1
    What exactly do you mean with "execution order"? What do you think this code does? Also to make this work as intended see the duplicate (tldr: declare `i` in the for loop `for(let i` ...) – Jonas Wilms May 03 '20 at 09:44
  • I mean where i's value come from? In normal I think i is from 5 to 0, but it does not. – kinjia May 04 '20 at 10:26

0 Answers0