In Memory Storage
Index
Home
Understanding the JavaScript Call Stack
JavaScript Error Messages
Understanding the JavaScript Call Stack
- What is a ‘call’?
- Function invocation
- How many ‘calls’ can happen at once?
- In V8, the number of recursive calls you can make depends on two quantities: the size of the stack and the size of the stack frame (holding parameters and local variables).
- What does LIFO mean?
- Last in First Out

-
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?
- A stack overflow occurs when there is a recursive function (a function that calls itself) without an exit point. The browser (hosting environment) has a maximum stack call that it can accomodate before throwing a stack error.
JavaScript Error Messages
- What is a ‘reference error’?
- This is as simple as when you try to use a variable that is not yet declared you get this type os errors.
console.log(foo) // Uncaught ReferenceError: foo is not defined
- 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.
JSON.parse( {'foo': 'bar'} ) // Uncaught SyntaxError: Unexpected token o in JSON at position 1
- 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.
var foo= [] foo.length = foo.length -1 // Uncaught RangeError: Invalid array length - What is a ‘tyep 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.
var foo = {} foo.bar // undefined foo.bar.baz // Uncaught TypeError: Cannot read property 'baz' of undefined - What is a breakpoint?
- A break point is a point set in your code to have it pause execution which you can then step through one line at a time.
- What does the word ‘debugger’ do in your code?
- The breakpoint can also be achieved by putting a
debuggerstatement in your code in the line you want to break.
- The breakpoint can also be achieved by putting a