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

Chapter 4. Working with Functions > Passing Values to Functions

Passing Values to Functions

As I mentioned earlier, one of the main reasons to use functions is to gain control over when some chunk of JavaScript code gets executed. In the previous section, for example, you saw that it's easy to use functions to set things up so that code doesn't run until the user clicks a form button.

However, there's another major reason to use functions: To avoid repeating code unnecessarily. To see what I mean, consider the two functions from Listing 4.2:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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