• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Working with Functions > Where Do You Put a Function?

Where Do You Put a Function?

For most applications, it doesn't matter where you put your functions, as long as they reside within a <script> block. However, one of the most common uses of functions is to handle events when they're triggered. It's possible that a particular event might fire when the page is loading, and if that happens before the browser has parsed the corresponding function, you could get strange results or an error. To prevent that, it's good practice to place the script containing all your functions within the page's header section (or within an external JavaScript file).

→ I talked about external JavaScript files earlier in the book; see "Creating External JavaScript Files".


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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