Javascript execution order with setTimeout()
问题 Say that I have the following code: function testA { setTimeout('testB()', 1000); doLong(); } function testB { doSomething(); } function doLong() { //takes a few seconds to do something } I execute testA() . I have read that Javascript is single-threaded. What happens after 1000 milliseconds, when the timeout for testB() is reached? Some possibilities I can think of: testB() is queued up to execute after doLong() and anything else it called have finished. doLong() is immediately terminated