Tham khảo sách 'javascript bible_ chapter 45', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Debugging Scripts One of the first questions that an experienced programmer asks about a programming environment is what support is there for debugging code. Even the best coders in the world make mistakes when they draft programs. Sometimes the mistakes are a mere slip of a finger on the keyboard other times they result from not being careful with expression evaluation or object references. The cause of the mistake is not the issue finding the mistake and getting help to fix it is. Some debugging tools are now available for the latest browsers. Because the debuggers must work so closely with the internal workings of the browser the tools so far have come from the browser makers themselves. While this chapter shows how Netscape s script debugger works most of the discussion is of value even if you debug your scripts the old-fashioned way by understanding the error messages. Syntax versus Runtime Errors As a page loads into a JavaScript-enabled browser the browser attempts to create an object model out of the HTML and JavaScript code in the document. Some types of errors crop up at this point. These are mostly syntax errors such as failing to include a closing brace around a function s statements. Such errors are structural in nature rather than about values or object references. Runtime errors involve failed connections between function calls and their functions mismatched data types and undeclared variables located on the wrong side of assignment operators. Such runtime errors can occur as the page loads if the script lines run immediately as the page loads. Runtime errors located in functions won t crop up until the functions are called either as the page loads or in response to user action. Because of the interpreted nature of JavaScript the distinction between syntax and runtime errors blurs. But as you work through whatever problem halts a page from In This Chapter Identifying the type of error plaguing a script Interpreting error messages Preventing problems