Archive for August 14, 2007

How to Create a Function in JavaScript

Posted in JavaScript on August 14, 2007 by Joey

A function can be created in JavaScript by using the function statement, as follows:

function CalculateTotal(intInput)
{
  var intTotal = 0;
  intTotal = intInput*2;
  return intTotal;
}

To call this function in JavaScript code, simply do this:

CalculateTotal(4);

The curly braces are required as part of the function statement.