How to Create a Function in JavaScript

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.

One Response to “How to Create a Function in JavaScript”

  1. only just starting to learn javascript so this will be cool to keep checking back here. thanks

Leave a Reply