View on GitHub

reading-notes

Observations and questions from reading assignments.

The Call Stack

Home

A call stack is a mechanism for an interpreter to keep track of its place in a script that calls multiple functions - what function is currently being run and what functions are called from within that function.

Example

The above code would execute like this:

  1. Ignore all functions, until it reaches the greeting() function invocation.
  2. Add the greeting() function to the call stack list. Example
  3. Execute all lines of code inside the greeting() function.
  4. Get to the sayHi() function invocation.
  5. Add the sayHi() function to the call stack list. Example
  6. Execute all lines of code inside the sayHi() function, until reaches end.
  7. Return execution to the line that invoked sayHi()and continue executing the rest of the greeting() function
  8. Delete the sayHi() function from our call stack list. Example
  9. When everything inside the greeting() function has been executed, return to its invoking line to continue executing the rest of the JS code.
  10. Delete the greeting() function from the call stack list. Example

Source: MDN