Declaring variables and functions

To declare a variable, use var before the variable name.

To declare a variable (globally or locally), use var in front of the variable name. IBM® Product Master variables can take any kind of supported objects such as string, number, catalog, and collaboration area. However, you do not need to specify the object type when you declare a variable. The variable is assigned an object type when it is assigned. Following are four examples of declaring variables:
//for number and String
   var intVar = 5;
   var strVar = "abc";

  //for objects Catalog and CollaborationArea
   var ctgVar = getCtgByName("My Catalog");
   var caVar = getColAreaByName("My CA");

  //for HashMap
   var hmVar = []; 
          hm["CA"] = "California";
          hm["NY"]	= "New York";

//for an array
  var arrayVar = [];
         arrayVar[0] = "item1";
         arrayVar[1] = "item2";
or arrayVar.add("item3");
To declare a function inside a script, use the word function before the function name, then list the parameters that are required for this function. For example, to declare a function that is named add, which takes in two numbers and returns the sum:
function add(a, b)
{
   return a + b;
}