We have 5 statements in a line and If we have a set timeout in the 3 statement it will executed after all the remaining statement got executed. I’m looking to execute the each statement line by line even If we have a set timeout in-between the code.
Example:
We have some statements
console.log("A");
setTimeout(console.log("B"), 1000);
console.log("C");
The expected output is A C B but I want to print is a A B C.
Any thoughts on this?
2
Answers
I assumed your setTimout was incorrect since it WILL execute the console.log immediately.
To do what you want, you need to replace console and setTimeout
you need to chain the timeouts, something like this (treat this as a proof of concept, but it is tested)