Debugging Flashcards
What’s a breakpoint?
A point of code where the debugger will automatically pause the JavaScript execution. (only if debugger is open in chrome)
What’s it called when there is a point of code where the debugger will automatically pause the JavaScript execution. (only if debugger is open in chrome)
breakpoint
What happens when a function declaration is made into a breakpoint?
You can’t make a function declaration a breakpoint. Function and variable declarations are done before the code is run through. They are not options to make breakpoints.
Create a conditional breakpoint
Can it use variables and functions of the js file?
Right click, edit breakpoint, create script
Yes
Write a statement direction in code that will pause the code.
How does it behave
debugger;
IF debugger is open in chrome, it will pause at that line. It becomes a sort of breakpoint but it cannot be paused or removed like breakpoints created in chrome.
From code:
debugger;
let x;
What happens when you add:
- x
- console.log(‘apple’);
To the watch list
x will wait for the variable to be assigned. Return <not available> then return undefined
With console.log(‘apple’) it can evaluate the expression from the beginning (and returns undefined)
How to watch a variable change as the code goes on
Watch an expression under Sources > Watch
With code: debugger; let myArray = [1, 2, 3]; What happens when you add: - myArray[1] - myArray[6] To the watch list
They both start as <not available>
when the array is created,
- myArray[1] becomes 2
- myArray[6] becomes undefined
What happens if you declare 2 values into the same variable: let x = 123; let x = 'apples'; And make each one a breaking point?
The code breaks before the debugger even starts.
Variable names are set aside (but not assigned) before the script starts