7.2 Debugging


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 the number of parameters?

  7. Is the function supposed to return a value? Did you remember to provide a variable or a place in the expression to hold the returned value?

  8. Did you define and call the function from within a JavaScript program?

Figure 7.12 shows function errors displayed by the JavaScript Console in Netscape. These error messages make troubleshooting your scripts much easier.

Figure 7.12. Function errors in the JavaScript Console (Netscape).

graphics/07fig12.jpg



JavaScript by Example
JavaScript by Example (2nd Edition)
ISBN: 0137054890
EAN: 2147483647
Year: 2003
Pages: 150
Authors: Ellie Quigley

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net