1function timeout() {
2 setTimeout(function () {
3 // Do Something Here
4 // Then recall the parent function to
5 // create a recursive loop.
6 timeout();
7 }, 1000);
8}
1var array = [1, 2, 3, 4, 5]for(var i = 0; i < array.length; i++) { setTimeout(() => { console.log(array[i]) }, 1000);} // i = 5
1// make sure to use "let" and not "var" if you want to capture
2// the value of the external variable in a closure
3
4 for (let i = 0; i < 5; i++) {
5 setTimeout(() => console.log(i), 0);
6 }