let timer = () => {
for(let i = 0; i < 5; i ++) {
setTimeout(() => {
console.log(i)
}, i * 1000)
}
}
timer();
code above will print 0, 1, 2, 3, 4 in 1000ms interval
and if I change let i = 0 into var i = 0, timer() will pring '5' five times in 1000ms interval. So far so good, and I know the differences between let and var
But now I want to print 0, 1, 2, 3, 4 in 1000ms interval, and not using let keyword, so what should I do?
I think I might need to use closure, but I don't know how.
edit: by not using let I mean use var instead