For a long time, everyone has been saying that Javascript is single-threaded. The browser has only one thread running at any time. JavaScript program.
However, I don’t know if you have any doubts - isn’t our setTimeout (similar to setInterval and Ajax) executed asynchronously during the programming process? ! !
For example:
Run the code and open the chrome debugger, you will get the following results
This result is easy to understand, because the content in my setTimeout is executed after 100ms. Of course, a is output first, then c, and then b in setTimeout is output after 100ms.
Hey, isn’t Javascript single-threaded? Can it be multi-threaded? ! !
Actually, no. setTimeout does not break the single-threaded mechanism of JavaScript, it is actually single-threaded.
Why do you say this? Then you have to understand what setTimeout is.
Please look at the code below and guess the result: