Call-stack
A stack data structure that holds the information of the functions called within a program that allows transfer of the application control from these functions to the main process after code inside the functions has been executed.
Example
function greet(who) {
console.log("Hello " + who);
}
greet("Harry");
console.log("Bye");
Breakdown
- Interpreter receives call to
greet()
- Goes to the definition of this function (
function greet(who)...
) - Executes the
console.log
within this function - Returns to the location that called it (
greet("Harry")
) - Finds that there is nothing else to do in this function so moves to next function: the
console.log("bye")
- Executes
- Returns to line that called it. Finds nothing else to do. Exits program.