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

Chapter 15. Combining Statements into Fu... > Passing Information to Functions in ...

Passing Information to Functions in Arguments

The displayError() function in the “Calling Functions” section earlier in this chapter can display only one message: "Error!". Suppose you want to give the user more specific information about the error. You can do that, without creating a separate function for each error, by passing an argument to the displayError() function. In the following example, the argument is named arg. The arg parameter exists in memory only for the duration of the function. When the function terminates, arg disappears. It completed its task in changing the errorText variable.

function displayError(arg) { 
     errorText = arg; 
} 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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