HTML and CSS Reference
For a discussion on how functions behave as objects. See “Classes and User-Defined
Functions” on page 182 in Chapter 8, “Objects.”
time to introduce some debugging techniques. As your programs grow, so do your
chances to create errors. Getting to know how to deal with these problems will save you
much time and frustration.
When working with functions there are some simple syntax rules to watch for:
1. Did you use parentheses after the function name?
2. Did you use opening and closing curly braces to hold the function definition?
3. Did you define the function before you called it? Try using the typeof operator
to see if a function has been defined.
4. Did you give the function a unique name?
5. When you called the function is your argument list separated by commas? If
you don't have an argument list, did you forget to include the parentheses?
6. Do the number of arguments equal to the number of parameters?
7. Is the function supposed to return a value? Did you remember to provide a vari-
able or a place in the expression to hold the returned value?
Firefox. This is a very useful debugging tool for immediate error checking. Just click the
Tools menu and go to Error Console. These error messages make troubleshooting your
scripts much easier. Figures 7.18 through 7.20 show errors in other browsers.