Javascript – Why setTimeout is executing this way
Code: setTimeout(() => console.log("1"), 1000) const startTime = Date.now() while (Date.now() - startTime < 5000); setTimeout(() => console.log("2"), 0) setTimeout(() => console.log("3"), 0) The output of this sample is: 2 3 1 Why it works this way ? In this…