Debugging and Error Handling Flashcards
8 types of errors
Error: runtime error
ReferenceError
SyntaxError
TypeError - invalid type, can’t be used there
EvalError - when using eval()
InternalError - represents an internal error in the JS engine; for e.g. excessive recursion
RangeError - numeric variable outside of its valid range
URIError - error when encoding or decoding an invalid URI
console API
contains several methods to aid in debugging
console. log()
console. error()
console. info()
debugger statement
can be used in code to set a breakpoint
additional console methods
console. warn() - writes a warning
console. table() - writes an object as a table
console. group() - creates a new inline group, which indents the output by an additional level
console. groupEnd() - exits the current inline group
console. assert() - writes an error messages if the specified expression is false
console. trace() - writes a stack trace to the console
console. time() - starts a timer
console. timeLog() - logs the value of the specified timer
console. timeEnd() - method ends a timer
types of breakpoints
line-of-code: allows pausing code execution before a specific line of code; it can also be conditional
DOM change: pauses code execution on the code that changes a DOM node or its children
XHR / Fetch: pauses code execution when the request URL of an EXR contains a certain string
Event Listener: pauses on the event listener that runs after a specific event is executed
exception: pauses on the line of code that throws a caught or uncaught exception
function: pause code execution when a specific function is called
setTimeout()
non blocking
3 valid states of promises
pending, fulfilled, rejected
promise methods
Promise.all - accepts an array or promises and returns a new promise; it is resolved when all the specified promises are resolved
Promise.allSettled - static method accepts an array of promises and returns the status and value/error for each promise
Promise.race - returns the first settled promise
Promise.any - when one of the promises is fulfilled, a single promise is returned
Promise.resolve - returns a new promise that resolves with the specified object
Promise.reject - returns a new promise that is rejected with the specified error
stack
call stack contains functions that are being processed in which each function is stacked as a frame. after being processed, the function is popped out the call stack
heap
objects that are created during runtime are allocated in a heap, which is a term used to describe a large region of memory in the running machine
queue
message queue or callback/event queue
where an async callback waits to be pushed by the event loop into the call stack for processing
specifying the events to monitor
monitorEvents three ways of specifying the event or events to monitor for a given object -event name -array of events -event type