H I O X INDIA
Javascript Tutorial
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch Portuguese Japanese தமிழ்
 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
More about Javascript
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.

privacy policy     license     sitemap
© 2004-2010 HIOX INDIA

Other Links