H I O X INDIA
Javascript Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java-Script Tutorial
Introduction
Variables
Operators
Statements
Loops
Functions
Objects
Arrays
Browser Objects
Form DOM
Ask Your Doubts
Feedback





Function with Arguments


Topic

Using or Passing parameters to a function?



Explanation

Function with Parameters:
Syntax:
function name(parameter 1,parameter 2,...)
{
     // set of statements that will be executed
}


        In many cases we pass parameters or arguments to functions, these arguments will be used inside the function for required calculations. For an example we will use two numbers to add, subtract using function.

Here we write separate function for each operations add, subtract.

Example Code:
<script language="javascript">

function add(number1, number2)
{
     var c = number1+number2;
     document.write(" ---- This added value is ---- "+c;
}

function sub(number1, number2)
{
     var c = number1-number2;
     document.write(" ---- This subtracted value is ---- "+c;
}

var a = 7;
var b = 3;
add(a,b);
sub(a,b);
</script>


Result:

Here you can clearly see that the two functions where invoked as "add(a,b);" and "sub(a,b);" where a and b are defined variables. You can even call the function directly with the variables as say "add(9,1);".

A function can be invoked any number of times with any proper value.


        Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

others

privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Other Links