Previous
While Loop
ABC of JavaScript : A JavaScript Tutorial
Functions
Next
Object Oriented JavaScript

Functions

Syntax:
function NAME([ARGUMENT] [,ARGUMENT] [,...]) {
BODY
}

A function will execute all the statments inside the body when it is called. Javascript functions can take arguments and return values. A value is returned using the return keyword -
return 1
This will return the value of - you guessed it - 1.

Lets see an example that will add two numbers - extreamly useful if you have forgotten how to add.

Another way of doing this is by calling the function from within the alert function.

alert("The sum of 4 and 5 is "+add(4,5))

Previous
While Loop
Contents Next
Object Oriented JavaScript