Skip to content

Instantly share code, notes, and snippets.

@happymishra
Last active June 16, 2019 07:00
Show Gist options
  • Save happymishra/437237ca0a3ccf70219c603e62a7012a to your computer and use it in GitHub Desktop.
Save happymishra/437237ca0a3ccf70219c603e62a7012a 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 atleast after 1 sec")
}
setTimeout(setTimeoutFunction, 1000)
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