User defined function: These functions are defined by user. User defined function should not match with pre defined functions. User can define the function in four types.
Normal function:
Syntax:
function function name()
{
//ststements;
}
Example:
function my function()
{
var a=10;
var b=20;
var c=a+b;
document.write(“normal function”=+c);
}
my function();
document.write(“<br>”);
Function with arguments:
Arguments: arguments is called function variables arguments. Defined in function definition, when the user call the function, it will pass the values to variables values are called parameters.
Syntax:
function.function name(arg1,arg2,….)
{
document.write(arg1,arg2)
}
function name(par1,par2….)
Example:
function.my function2(a,b)
{
var(=a+b);
document.write(c);
}
my function2(50,20);
Function with return value:
Return: It is used to stop the function execution, It can write some value also(return.false;).
Example:
function.my function3()
{
document.write(“ststement01<br>”);
return’name’;
}
var x=my function3()
document.write(x);
Function with arguments and return:
Example:
function my function4(a)
{
document.write(“ststement01<br>”);
return a*a;
}
document.write(“ststement01<br>”);
var y=my function4(100);
document.write(y);

No comments:
Post a Comment