Previous
While Loop 
Next
Object Oriented JavaScipt Programming 
ABC of JavaScript : An Interactive JavaScript Tutorial
Function

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 
Next
Object Oriented JavaScipt Programming 
blog comments powered by Disqus