Source: The Call Stack defined on MDN
Source: The JavaScript Call Stack - What It Is and Why It’s Necessary
Source: JavaScript error messages && debugging
Mechanism for an interpreter (browser / server) to keep track of its place when running code that calls multiple functions.
Single threaded and syncronous
Begin with empty call stack. When a function is invoked, its added. After it executed it’s removed. End with empty call stack.
LIFO (Last in, first out)
function greeting() {
// [1] Some codes here
sayHi();
// [2] Some codes here
}
function sayHi() {
return "Hi!";
}
// Invoke the `greeting` function
greeting();
// [3] Some codes here
Call stack
greeting()
greeting()
to call stack
greeting
greeting()
sayHi()
invocatonsayHi()
to call stack
sayHi
greeting
sayHi()
sayHi()
and compelete execution of greeting()
sayHi()
from call stack
greeting
greeting()
greeting()
from call stack
EMPTY
console.log()
debugger:
statement to see historytry...catch