Skip to content

Instantly share code, notes, and snippets.

@happymishra
Last active June 9, 2019 19:34
Show Gist options
  • Save happymishra/d15fd3a769cebbd069cbc99aba110b80 to your computer and use it in GitHub Desktop.
Save happymishra/d15fd3a769cebbd069cbc99aba110b80 to your computer and use it in GitHub Desktop.
var log = console.log
log("Inside global execution context")
function functionOne() {
log("Inside function one")
function setTimeoutFunction() {
log("Inside setTimeoutFunction: I will be executed after ECS become empty." +
"Though my waiting time is zero")
}
// O is passed as time for setTimeout, but this method will execute only after
// ECS is empty. As time passed is zero, as soon as it moves to Web API container
// it will be moved to the callback message queue
setTimeout(setTimeoutFunction, 0)
for(var i = 0; i < 10000000000; i++) {
// Blocking code. This makes the for loop to execute for more than 1 second
// Still setTimeoutFunction is not executed. It gets executed only after
// last statement of the code
}
log("Exiting functionOne")
}
functionOne()
log("Exiting global execution context")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment