Functions are used to re use the code by call using function
name
JS supports two types of functions
1. User Defined Functions
- These functions are defined by the user the scope of these functions is inside the application or project
- JS supports function overriding that means if any function having with same the functions will override each other.
- User defined any concrete methods but not absolute methods
- Abstract Method: If any method having any definition without body is called abstract method
- Syntax: Function Function Name();
- Concrete Method: If any methods having both definition and implementation is called concrete method
Syntax: Function Function Name() {
Statements;
}
Types of User Defined Functions
a) Functions with Arguments
b) Functions with Retune
c) Functions with Arguments and Retune
<html>
<head>
<script
language="javascript">
document.write("<h1>Normal
Functions</h1>");
function
test1(){
var
a=10;
var
b=20;
document.write(a+b);
}
test1();
document.write("<h1>Functions
With Arguments</h1>");
function
test2(a,b){
document.write(a+b);
}
test2(10,20);//call
by value;
var
x=100;
var
y=200;
test2(x,y);//call
by reference
document.write("<h1>Functions
With Return</h1>");
function
test3(){
document.write("statement01<br>");
return
false;
}
var
r=test3();
document.write(r);//false
document.write("<h1>Functions
With Argument & Return</h1>");
function
test4(a){
return
a*a;
}
var
r=test4(20);
document.write(r);//400
</script>
</head>
<body>
</body>
</html>
2. Pre Defined Functions
These functions is defined in JS libraries we can use this
functions any ware directly JS supports
four types of functions
a) String Functions
b) Array Functions
c) Math Functions
d) Date Functions
No comments:
Post a Comment