Java Script


JavaScript Tutorial


Admission Enquiry Form


Function with arguments and with return in JavaScript

When function takes a value as an argument and also return a value.


Syntax Function with arguments and with return value

function functionName([arg1, arg2, ...argN])
{  
 //statements to be executed  
 //return statement;
}  

Example of Function with arguments and with return:

<html>
<head>
<title>Function with argument and with return</title>
</head>
<body>
<script>
function sum(n1,n2)//body of function
{
var ans;
ans=n1+n2;
return (ans);
}
var x,y,res;
x=10;
y=20;
res=sum(x,y); //calling function
document.write("Sum of numbers is "+res);
</script>
</body>
</html>

Output:

Sum of numbers is 30