Think you might be in the wrong place? Go home!
A ‘call’ refers to the execution of a function in a programming context. When a function is called, the program transfers control to the function, and the statements inside the function are executed.
In a single-threaded environment, only one call can happen at a time. This is because JavaScript follows a single-threaded, synchronous execution model. However, it’s important to note that asynchronous operations, such as callbacks, can occur concurrently without blocking the main thread.
LIFO stands for “Last In, First Out.” It is a principle used in data structures, and in the context of a call stack, it means that the last function that was called is the first one to finish and return control to the calling function.
function first() {
second();
console.log('Inside first');
}
function second() {
third();
console.log('Inside second');
}
function third() {
console.log('Inside third');
}
first();
Call Stack:
| |
| third | <--- current function (top of the stack)
| second |
| first |
-----------
A Stack Overflow occurs when the call stack exceeds its maximum size due to an excessive number of function calls. This often happens with recursive functions that don’t have a proper base case, leading to an infinite loop of function calls. When the stack limit is reached, the browser or runtime raises a “Maximum call stack size exceeded” error, resulting in a stack overflow.
Information gathered using ChatGPT