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

Chapter SATURDAY MORNING. Learning the B... > Streamlining Your Scripts with Funct...

Streamlining Your Scripts with Functions

A function is a collection of statements that performs a given task. Most functions are defined in the head section of HTML pages. Putting your functions in the head section is a good idea for two reasons: The first is that you’ll always know where your functions are because they’re in a common location. The second reason is that the head section always executes first, ensuring that functions are available when needed later in the script. If a JavaScript statement attempts to call a function before the browser has loaded it, an error will occur because the function is technically still undefined. I also recommend putting your functions in a common location in your WSH JScript files.

NOTE

You may be wondering what the difference is between a function and a method.The answer is not much. Methods are simply functions that have been predefined. Methods are associated with specific objects, meaning that each object provides its own collection of methods that you can call from within your scripts.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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