This topic is important to me because I want to be able to use error handling correctly and use in memory storage well.
The JS engine, is a single-threaded interpreter comprising of a heap and a single call stack.
Call stack is used for function invocation(call).
Since the call stack is single, functions execution is done one at a time. Top to bottom. The call stack is synchronous.
Understanding the call stack is vital to Asynchronous programming.
In Asynchronous JS, we have a callback function, an event loop and a task queue.
A Call Stack is a data structure that uses Last In, First Out principe to temporarily store and manage function calls.
Last In, First Out (LIFO) - Means that the last function that gets pushed into the stack is the first to be pop out when the function returns.
When a function is invoked, the function, its parameters, and variables are pushed into the call stack to form a stack frame. This stack frame is a memory location in the stack. The memory is cleared when the function returns as it pops out.
A Stack Overflow occurs when there is a recursive function(a function that calls itself) without an exit point.
IN SUMMARY: Javascript is single threaded- only one at a time. Code execution is synchronous. A function invocation creates a stack frame that occupies a temporary memory. Works as a LIFO.
Error messages are given to us in coding to help diagnosis whats wrong with our code!
Reference Errors -When you try to use a variable that is not yet declared. Or don’t give it a let,const,var.
Syntax Error - This occurs when you have something that cannot be parsed in terms of syntax.
Range Errors - Trying to manipulate an object with an length and giving it an invalid length.
Type Errors - This shows up when the types (number,string etc) you are trying to use or access are incompatible , like using a property of an undefined type of variable.
To debug your code, you can console.log your code to figure out what you want.
You can also use your debugging tools that come with your browser to select breakpoints and more.
I want to know more about the call stacks, and how it changes with the languages you use.
I want to know how powerful a language can be if it can use more than one thread.