This Repo required for Asac labs class 2
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.
Data structure that uses (LIFO): When we say that the call stack, operates by the data structure principle of Last In, First Out, it means that the last function that gets pushed into the stack is the first to be pop out, when the function returns.
The JavaScript engine (which is found in a hosting environment like the browser), is a single-threaded interpreter comprising of a heap and a single call stack. The browser provides web APIs like the DOM, AJAX, and Timers.
The call stack is primarily used for function invocation (call).
function firstFunction(){
console.log("Hello from firstFunction");
}
function secondFunction(){
firstFunction();
console.log("The end from secondFunction");
}
secondFunction();
the output for the above function will be:
"Hello from firstFunction"
"The end from secondFunction"
The call slack list:
Then:
Then:
calling a function inside itself (just like infinite loops)
A stack overflow occurs when there is a recursive function (a function that calls itself) without an exit point.
The best way is to use console.log()
or by putting a debugger;
statement at the line of code you want to break.
Don’t forget to remove all debugger;
lines before ACP