Main Page

JavaScript Verifier

As you can see, this reduces the amount of code contained in the
divide()
function and also makes it
clearer what the developer was thinking when writing this function.
The JavaScript Verifier
Douglas Crockford, a software engineer, wrote a small tool called jslint — The JavaScript Verifier. The
purpose of jslint is to point out unprofessional JavaScript syntax and possible syntax errors. You simply
paste your JavaScript code (either pure JavaScript code or code enclosed in a
<script/>
tag) into a text
box and click the jslint button. The tool then outputs warnings and errors about your code underneath.
The types of warnings provided by jslint are in line with the professional standards mentioned through-
out this book. You receive a warning if the code contains an inappropriate coding technique, such as the
following:
?
A statement (
if
,
for
,
while
, and so on) that doesn’t use block notation (see Chapter 2,
“ECMAScript Basics”)
?
A line that doesn’t end with a semicolon
?
A
var
statement declaring a variable name that is already in use
?
The
with
statement (for reasons to avoid
with
, see Chapter 2)
The JavaScript Verifier is available online at
http://www.crockford.com/javascript/jslint.html
,
and it can also be downloaded in its original source code for your own use.
Debuggers
Programmers used to developing in languages such as C, C++, Java, and Perl know that debugging is
an important part of the development process. These developers rely heavily on debuggers for such pro-
gramming languages to aid in tracking down errors in their code. Most languages offer some type of
debugger, from simple command line programs to exhaustive GUI layouts. Although JavaScript itself
doesn’t have a debugger, both Internet Explorer and Mozilla have debuggers available.
Microsoft Script Debugger
The Microsoft Script Debugger is a free utility available from Microsoft’s Web site. To download it, go to
http://www.microsoft.com/downloads/search.aspx?categoryid=10
and type
script debugger
into the Search box. The results list comes up with Script Debugger for Windows NT, 2000, XP. Click that
link and click the Download button. Run the installation program and then restart Internet Explorer.
Notice a new menu item that appears under the View menu called Script Debugger. This provides
options for running the debugger.
Running
You can run the Microsoft Script Debugger in a number of ways. First, you can open it directly by select-
ing View
?
Script Debugger
?
Open, which opens the debugger with no information loaded. The second
method is to select View
?
Script Debugger
?
Break at Next Statement, which opens the debugger before
432
Chapter 14
17_579088 ch14.qxd 3/28/05 11:41 AM Page 432


JavaScript EditorFree JavaScript Editor     Ajax Editor


©