What is the Call Stack?
Why should you care?
Call Stack, Step by Step
What happens when the above code runs:
- The first function call is foo() which acts as our entry-point and creates the first execution context added to the call stack
- foo() then calls bar() — bar() gets added on to call stack
- bar() returns to print “Hello from bar” to the console
- bar() has finished executing and is then popped off the call stack
- The second execution context of foo() is reached
- foo() prints “Goodbye from foo” to console
- foo() has finished executing and is popped off the call stack — clearing the stack and terminating the program