• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Q&A

Q1:Why are some errors displayed after the script runs for a time, while others are displayed when the script loads?
A1: The JavaScript interpreter looks at scripts in the body or heading of the document, such as function definitions, when the page loads. Event handlers aren't checked until the event happens. Additionally, a statement might look fine when the page loads, but will cause an error because of the value of a variable it uses later.
Q2:What is the purpose of the location.reload statements in the number guesser script?
A2: This is an easy way to start a new game because reloading the page reinitializes the variables. This results in a new number being picked, and the default “Guess a Number” message is displayed in the hint field.
Q3:The JavaScript console in Netscape is useful for testing JavaScript commands when I'm not sure of the syntax. Is there an equivalent in Internet Explorer?
A3: Not a built-in one, but I've created a JavaScript-based console that works in Netscape or Internet Explorer. It can't display errors like Netscape's console, but it is useful for testing commands interactively. You can find it at this book's Web site: http://www.jsworkshop.com/


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint