function test(str) {
setTimeout(() => {
console.log(str);
}, 10000);
}
let i = "1";
test(i); //test 1
console.log(i, "sync");
i = "2";
test(i); //test 2
console.log(i, "sync");
Is it because of the closure that test 1 and 2 print 1 and 2 in sequence? If I don't write setTimeout inside the function, the result is the last i value