Functions and variables

Functions and variables refer to the variable that is being called out to in the script.

If you declare var c = 10; inside the function, then c inside the function has just that scope. Otherwise, the function gets any variable that is defined outside of it.

Variable scope

The following script is an example of a variable scope:
var c = 10;

function add(a, b)
{
   // var c = 5;
   c++;
   out.writeln("c is " +  c);
   return a + b;
}


var sum = add(1,2);
out.writeln("Sum is " + sum + ", c = " + c);