Functions
Functions are used to store a list of scripts that will be used more than once.
A function can be called as many times as you want and can even be called with arguments.
Defining functions
function functionName([args]) {
// do something
}
Example 1
function addNumbers(a,b) {
var sum = a+b; // adds a and b and then stores their total in the variable called sum
return sum; // returns the value of sum
}
Example 2
function alertUser(msg) {
alert(msg); // shows a alert popup with the given message msg
}
|