This is a question about how you have the implementation of function2()
set up. However almost all javascript is executed in a sequential manner unless a setTimeout()
, setInterval()
or other event driven mechanic is used for its execution. This however is not true multi-threading, put simply it cheats by just waiting for the rest of the code to execute
However what you have there is saying you execute function2()
then wait for it to complete and then execute test = 1
, You can almost think of having function2()
's body as being inserted at the beginning of the function1()
body. The keyword being "almost". But that should give you an idea of how the JS is executed. However, V8 (Google's javascript engine) can support pseudo-multithreaded environments. While this can technically be done with in normal run of the mill JS it becomes a very big mess very quickly for more information take a look at this Tutorial.