Last active
June 16, 2019 06:42
-
-
Save happymishra/5e4533bc85544bfd55f44ba3c048f817 to your computer and use it in GitHub Desktop.
Executuon context stack example
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
console.log("Inside global execution context") | |
// 'a' will be stored on ECS as it's a primitive value | |
var a = 10; | |
// Only reference of functionOne will be stored inside stack. | |
// funtionOne definition itseld will be stored on heap | |
function functionOne() { | |
console.log("Inside functionOne exectuon context") | |
// 'b' will be stored on ECS as it's a primitive value | |
var b = 5; | |
// Only object reference will be stored on the stack. | |
// Object itself will stored on heap | |
var obj = { | |
"name": "Virat", | |
"age": 30 | |
} | |
function functionTwo() { | |
console.log("Inside functionTwo exectuon context") | |
console.log("Exiting functionTwo exectuon context") | |
} | |
functionTwo() | |
console.log("Exiting functionOne exectuon context") | |
} | |
functionOne() | |
console.log("Exiting global execution context") | |
// Program Ends - Execution stack becomes empty. | |
// Heap memory may or may not be released, it depends on garbage | |
// collector |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment