This section is about using the FireFox debugger window with the debugger statement as the way to set breakpoints. The debugger window has a built in method of setting breakpoints, however at this time it seems to be very buggy so weíre not using it.
First, letís consider showing values of variables. You can just hover over them, but that gets old fast. If you notice in the value bubble that appears when you hover over a variable, there is a Watch option.
If you click on that, it adds the variable to the Watch Window which is on the right side of the debugger.
Setting watches is very useful since typically youíre only interested in a few variables at one time. For less used variables you can always just hover over it to get the value. You can also manually add watch expressions which can be statements in their own right. To do that,† right click on the watch window and select Add Watch Expression
Once youíve entered a watch you can edit it by double clicking on it and changing the expression.
Thereís another somewhat sneakier thing you can do with watches, you can directly change the value of a variable by clicking on the value and editing it. Here I changed count from 0 to minus 2. Notice that the other watch expression now has the value false since -2 isnít greater than -1.
This can sometimes be very handy if youíre debugging some code and perhaps missed a critical value inside a loop. Just change the value and let it run again.
At line 10 I added an if statement such that the debugger statement is only executed when count == 1. Notice the double equals signs, thatís used for comparisons whereas the single equals sign assigns a value to a variable.
NOTE: Single equals signs in If statements are VERY DANGEROUS. You may see this is existing code and there are a few times it makes sense, but far more often itís a bug waiting to happen. If I had used a single equals sign in this code, as shown below, the code would have gone into an infinite loop.
What would happen with this code with the single = on line 10 rather than the correct == or ===, is that on each loop, the if on line 10 would be executed. The count = 1 test in the if would be evaluated which, instead of testing if count equaled one, would assign the value 1 to the variable count. Apart from the program not actually counting down, the while loop starting at line 5 would never stop because count would always equal one, and one is greater than zero.