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

4. Variables, Functions, and Flow Control > 4.2. Creating a Named Function

Creating a Named Function

NN 2, IE 3

Problem

You want to define a function that can be invoked from any statement in the page.

Solution

For a function that receives no parameters, use the simple function declaration format:

function myFunctionName( ) {
    // statements go here
}

If the function is designed to receive parameters from the statement that invokes the function, define parameter variable names in the parentheses following the function name:

function myFunctionName(paramVar1, paramVar2[, ..., paramVarN]) {
    // statements go here
}

You can define as many unique parameter variable identifiers as you need. These variables become local variables inside the function (var declarations are implied). Following JavaScript’s loosely typed conventions, parameter variables may hold any valid data type, as determined by the statement that invokes the function and passes the parameters.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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