Understanding the JavaScript Call Stack
-
What is a ‘call’? At the most basic level, a call stack is a data structure that uses the Last In, First Out (LIFO) principle to temporarily store and manage function invocation (call).
-
How many ‘calls’ can happen at once? One call at a time.
-
What does LIFO mean? Last in, first out (LIFO).
-
Draw an example of a call stack and the functions that would need to be invoked to generate that call stack. function firstFunction(){ console.log(“Hello from firstFunction”); }
function secondFunction(){ firstFunction(); console.log(“The end from secondFunction”); }
secondFunction();
- What causes a Stack Overflow? The most-common cause of stack overflow is excessively deep or infinite recursion, in which a function calls itself so many times that the space needed to store the variables and information associated with each call is more than can fit on the stack.
JavaScript error messages
-
What is a ‘refrence error’? This is as simple as when you try to use a variable that is not yet declared you get this type os errors.
-
What is a ‘syntax error’? this occurs when you have something that cannot be parsed in terms of syntax, like when you try to parse an invalid object using JSON.parse.
-
What is a ‘range error’? Try to manipulate an object with some kind of length and give it an invalid length and this kind of errors will show up.
- What is a ‘type error’? this types of errors show up when the types (number, string and so on) you are trying to use or access are incompatible, like accessing a property in an undefined type of variable.
-
What is a breakpoint? The breakpoint can also be achieved by putting a debugger statement in your code in the line you want to break.
- What does the word ‘debugger’ do in your code? by putting a debugger statement in the code to identify JavaScript errors