Site hosted by Angelfire.com: Build your free website today!
Website Help

| HTML | CSS | JavaScript |

Soon to come:
XHTML, XML, ASP,
Home

JS Basics

JS Home
Introduction
Basics
Operators
Functions
Conditional
Looping

JS References

String Object
Array Object
Date Object
Math Object
Window Object
Frame Object
Form Object
Browser Object

JavaScript Functions

Define a function

To 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 function

Too 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 statement

Function'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
  	 }
  	
fastadvert.com


fastadvert.com - make money with your website