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

Q&A

Q1: Netscape displays the error message “missing semicolon before statement” when I try the function example.
A1: This is probably because you mistyped something. JavaScript is case-sensitive, so be sure you get the capitalization right. This specific error message will appear if you use the keyword Function instead of function.
Q2: What is the importance of the var keyword? Should I always use it to declare variables?
A2: A You only need to use var to define a local variable in a function, and then only if you want to ensure that a global variable of the same name is not used. However, if you're unsure at all, it's always safe to use var. Using it consistently will help you keep your scripts organized and error-free.
Q3: Is there any reason I would want to use the var keyword to create a local variable with the same name as a global one?
A3: Not on purpose. The main reason to use var is to avoid conflicts with global variables you may not know about. For example, you may add a global variable in the future, or you may add another script to the page that uses a similar variable name. This is more of an issue with large, complex scripts.
Q4: What good are boolean variables?
A4: Often in scripts you'll need a variable to indicate whether something has happened—for example, whether a phone number the user entered is in the right format. Boolean variables are ideal for this; they're also useful in working with conditions, as you'll see in Hour 7.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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