One simple option is use setInterval() method instead.
The setInterval will execute the code everytime as a loop until you break it with the clearInterval() method.
Example:
var index = 0;
let incrementEveryHalfSecond = setInterval(function(){
index++;
document.querySelector("body").innerHTML += index+'</br>';
if(index == 10) clearInterval(incrementEveryHalfSecond)
}, 500)
<body></body>
Observe that you decide break of loop, passing the variable that is store the setInterval method as parameter in the clearInterval method. Now you can create functions to get a better clear code.
w3schools documentation
Question answer:[from 100 to 1] I inverted the order of i to simplify, but you can also do with "100-i".
var myfunc03 = function (i) {
document.getElementById('d01').innerHTML += i+"<br>";
};
var myFunc01 = function() {
let i=100;
let incrementEveryOneSecond = setInterval(function(){
myfunc03(i);
if(--i == 0) clearInterval(incrementEveryOneSecond);
}, 1000)
};
myFunc01();
<span id="d01"></span>
i) from within a closure. When the timeout fires,iwill have changed to whatever the last one is.setTimeoutexpects aFunctionas the first parameter but you're passing the result ofmyfunc03(which isunderfinedbecause you're invoking it)