Functions : Function Definition : Function JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Function » Function Definition »

 

Functions













All function declaration must begin with the keyword function followed by the name of the function.

Parentheses are placed after the function name to hold arguments.

If more than one argument are used, use commas to separate the arguments.

If no arguments, leave the space between the parentheses empty.

Curly brackets are used to contain the code related to the function.

Curly brackets are not optional.

JavaScript uses call by value.












<html>
<SCRIPT LANGUAGE='JavaScript'>
<!--
    var aString = "A"
    var aNumber = 1;
    function test(aString, aNumber) {
      aString = "B";
      aNumber = 2;
      document.write("<BR><BR><BR><BR><BR>During function call:<BR>");
      document.write("aStringCopy=",aString,"<BR>");
      document.write("aNumberCopy=",aNumber,"<BR>");
    }

    document.write("<BR><BR><BR><BR><BR>Before function call:<BR>");
    document.write("aString=",aString,"<BR>");
    document.write("aNumber=",aNumber,"<BR>");


    test(aString,aNumber);


    document.write("<BR><BR><BR><BR><BR><BR><BR>After function call:<BR>");
    document.write("aString=",aString,"<BR>");
    document.write("aNumber=",aNumber,"<BR>");
    //-->
</SCRIPT>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Function
» Function Definition