Parameters In Functions
Function Function_Name([arg1 [, arg2 [, ... argN ]],]){
Function_Body
}
You can pass arguments to a function.
Parameters helps to pass informations/ arguments into the function.
The arguments can be either numbers or strings.
Output of the function depends on the arguments you give it.
Passing String
Passing Integer
Passing String
Example: 1
<html>
<head>
<script language="javascript">
function alertMe(string)
{
alert(string)
}
</script>
</head>
<body onload="alertMe('hi everybody,here I use parameter in function to pass argument')">
</body>
</html>
Example: 2
<html>
<head>
<script language="javascript">
function alertMe(string)
{
alert(string)
}
</script>
</head>
pass argument ')" onunload="alertMe('Good bye,have a nice day')";>
</body>
</html>
When you click “cross button” of the browser, not dialog box, the following alert box will appear in your browser:
Passing Integer
Example: 1
<script type="text/javascript">
function add(a,b)
{
x=a+b;
return x;
}
alert(add(3,4));
</script>
function add(a,b)
{
x=a+b;
return x;
}
alert(add(3,4));
</script>
Example: 2
<script type="text/javascript">
function add(a,b)
{
x=a+b;
return x;
}
alert(add(3,4));
alert(add(95,5));
</script>
function add(a,b)
{
x=a+b;
return x;
}
alert(add(3,4));
alert(add(95,5));
</script>
No comments:
Post a Comment