|
|
Tutorials

Javascript

|
Topic |
Using or Passing parameters to a function?
|
|
Explanation |
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.
|
| A Note |
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.
|
|
|
|