I had the following question on an interview. cannot see what's wrong with it.
The following code attempts to run 10 tasks sequentially and have a timeout of 1 second after each task. Given the following piece of code, please identify issues with it, and write a correct implementation for the original intention.
for (let i = 0; i < 10; i++) {
setTimeout(function() {
// Running some asynchronous tasks here
// ...
console.log("completed task id " + i);
}, 1000)
}