reading-notes

reading notes for code fellows


Project maintained by dLeigh01 Hosted on GitHub Pages — Theme by mattgraham

In Memory Storage

This is important because the ability to understand why your code is running the way it is and in what order/ what all the different errors refer to is essential in your ability to debug effectively.

Understanding the JavaScript Call Stack

The call stack is primarily used for function invocation. Since JavaScript is single-stack, functions are executed one at a time from top to bottom, making the call stack synchronous. A call stack uses the LIFO (last in first out) principle to temporarily store and manage function calls. A stack overflow occurs when there is a recursive function with no exit point, it will throw an error when the browser reaches the maximum call stack size.

  1. A call is when a function is invoked.
  2. Only one call can happen at a time.
  3. Last in First out
  4. functionOne () => {console.log('One')} functionTwo () => {functionOne(); console.log('Two')} functionTwo(); returns One Two because the second function is called at the end of the document, so it is pushed into the stack first, then it calls the first function, which is pushed into the stack after it, completes its task by logging one, pops out of the stack, and allows the second function to complete its task by logging two before poping out as well.
  5. A stack overflow is caused when a recursive function calls itself more times than the browser will allow.

JavaScript Error Messages

Types of error messages

The simplest way to debug your code is to console.log() the variables you want to check. You also could use a debugger tool and set breakpoints in your code where you want it to pause so you can check all your variables. If you add a debugger statement, you can see the history of the code before it reaches the breakpoint. The call stack is easier to navigate in debugging if you use appropriately named functions, as it won’t show the names of the parents functions to anonymous ones.

Try catch allows you to handle errors properly, giving your code a fallback route so the rest of it can still be executed. To avoid runtime errors, you can also use tools like quokka, eslint, and typescript.

  1. The variable you’re using hasn’t been declared.
  2. Something you’ve written can’t be parsed syntactically.
  3. Something with a length value has been accessed with an invalid length.
  4. The type of the thing you are attempting to access is incompatible with what you are doing.
  5. A breakpoint is a stopper you can place in the code that will pause it when you’re running a debugger.
  6. Debugger will act as a breakpoint with a code history.

Things I Want to Know More About

Quokka is something that sounds interesting, I may want to check that out at some point and see if iI like it.

[< table of contents]

[< home]