Java Reference
In-Depth Information
Finally, you look at the debugging tools in Microsoft's Internet Explorer (IE11), Firebug (an add‐on
for Firefox), Chrome's Web Inspector, and Opera's Dragonfly. You see how you can use these tools
to step through your code and check the contents of variables while the code is running, a process
that enables you to hunt for difficult bugs. You also take a briefer look at the debugging tools
available for Firefox.
d'oh! i Can't Believe i Just did that:
some Common mistakes
Several common mistakes are made by programmers. Some of these you'll learn to avoid as you
become more experienced, but others may haunt you forever!
undefined variables
JavaScript is actually very easygoing when it comes to defining your variables before assigning
values to them. For example, the following will implicitly create the new global variable abc and
assign it to the value 23 :
abc = 23;
Although strictly speaking, you should define the variable explicitly with the var keyword like this:
var abc = 23;
Your choice of whether to use the var keyword to declare a variable has a consequence on the
variable's scope; so it is always best to use the var keyword. If a variable is used before it has been
defined, an error will arise. For example, the following code will cause the error shown in Figure 18-1
in IE11 if the variable abc has not been previously defined (explicitly or implicitly):
alert(abc);
figure 18-1  
 
Search WWH ::




Custom Search