| HTML | CSS | JavaScript |XHTML, XML, ASP, |
JS BasicsJS HomeIntroduction Basics Operators Functions Conditional Looping JS ReferencesString ObjectArray Object Date Object Math Object Window Object Frame Object Form Object Browser Object |
JavaScript FunctionsDefine a functionTo define a function you use the function keyword. You give the function a name and any arguments you might have.
function firstFunction(argument1, argument2, etc){
[statement(s)]
}
Even if the function does not have any arguments, it MUST still have the parenthesis after the name.
function firstFunction(){
[statement(s)]
}
Arguments are variables used within the function, they are set when they are called. If a function is placed in the head section of the document, the function will be loaded as soon as the page starts before the function is called Calling a functionToo call a function you simply type the name of the function along with or without its arguments firstFunction(1,2,3) or secondFunction() The return statementFunction's which return a result must use the return statement in order for the variable's result to be passed to where it was called from.
function multiplyIt(2,3){
var answer = 2 * 3
}
|