Skip to content

Instantly share code, notes, and snippets.

@evillemez
Created March 29, 2014 18:22
Show Gist options
  • Save evillemez/9859465 to your computer and use it in GitHub Desktop.
Save evillemez/9859465 to your computer and use it in GitHub Desktop.
setTimeout(function() {
console.log("2 seconds");
}, 2000);
setTimeout(function() {
console.log("now??");
}, 0);
console.log("now");
@RKdev
Copy link

RKdev commented Mar 29, 2014

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"

@RKdev
Copy link

RKdev commented Mar 29, 2014

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