Functions

JavaScript allows you to package a block of code into a function, which is a subprogram that performs a particular task. To execute the block of code, you simply “call” the function that contains the code. By packaging code into a function, you can easily this common code in multiple elements and reports, which makes script maintenance much easier.

JavaScript functions behave a little differently than functions in other languages:

Input arguments do not require reference vs. value specification. (Primitive types are passed by value, whereas objects are passed by reference.)

Input arguments do not require data type specification

Return values are optional and do not require data type specification

function max(a,b) // -- Two input arguments

{

   if (a > b)

      return(a); // -- Return a because it is larger

   else

      return(b); // -- Return b because it is larger

}

To create and save a custom JavaScript function, see Using the Script Library.

<< Switch Statement © 1996-2013 InetSoft Technology Corporation (v11.5) 2.2 Editing Script >>