forked from phongvdoan/seattle-301d60
-
Notifications
You must be signed in to change notification settings - Fork 0
Read: 10
Dayne edited this page Dec 13, 2019
·
1 revision
Call stack defined:
A call stack is a mechanism for an interpreter (like the JavaScript interpreter in a web browser) 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, etc.
- When a script calls a function, the interpreter adds it to the call stack and then starts carrying out the function.
- Any functions that are called by that function are added to the call stack further up, and run where their calls are reached.
- When the current function is finished, the interpreter takes it off the stack and resumes execution where it left off in the last code listing.
- If the stack takes up more space than it had assigned to it, it results in a "stack overflow" error.
The key takeaways from the provided articles are:
- It is single-threaded. Meaning it can only do one thing at a time.
- Code execution is synchronous.
- A function invocation creates a stack frame that occupies a temporary memory.
- It works as a LIFO — Last In, First Out data structure.
In my own words: A call stack acts as a temporary library for function invocations (calls) and it manages the order in which they are deployed.