Created
March 29, 2014 18:22
-
-
Save evillemez/9859465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(function() { | |
console.log("2 seconds"); | |
}, 2000); | |
setTimeout(function() { | |
console.log("now??"); | |
}, 0); | |
console.log("now"); |
Or does the callback function to setTimeout only get pushed onto and popped from the stack when setTimeout is called?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case I miss you it goes "now" "now??" and then "2 seconds". I'm guessing that even though the setTimeout function is set to wait 0 seconds, you still have to wait for javascript to push setTimout to the stack, then the anonymous function to the stack. Then it would have to pop the anonymous function off, and the calling function after that - which have to happen slower than the console.log function that prints "now"