OBJECT BASED PROGRAMMING
Java Script is a very powerful object-based language, but not a full-blown OOP language.FUNCTIONS:
Functions are the central working units of javascript. Almost all the scripting code uses one or more functions to get the desired result. Functions are a convenient way for providing certain user defined functionality.Syntax of FUNCTION:
function funtionname(parameters/arguments)
{
- - - - - - - - - - - - - -;
- - - - - - - - - - - - - -;
Statements;
- - - - - - - - - - - - - -;
- - - - - - - - - - - - - -;
}Calling the FUNCTION:
We can call the function from any other place in our javascript code or say HTML document. After the function is executed, the control goes back to the next statement of calling function statement.Syntax for calling Function:
functionname(parameters/arguments(if any));
Arguments:
We can pass arguments to a function. These are variables, either numbers or strings, which are used inside the function.Returning a value:
Function can do is to return a value by using a return keyword.Example:
<html>
<head>
<script type="text/JavaScript">
function hello() //function without any arguments. This function shows an alert window on page.
{
alert("WELCOME TO PRUDRADEEP.BLOGSPOT.IN");
}
function product(a,b) // function with two arguments. This function returns the product of a and b.
{
return a*b; //This returns a*b or send the result back to the caller of function.
}
</script>
</head>
<body>
<script type="text/JavaScript">
hello(); //Hello Function callled.
product(5,6); //Product function called but on the page there is no result.
document.write(product(4,3)); //In this line we called the product function and passed the arguments in numbers. This line returns the result on Page.
</script>
</body>
</html>
BACK
To Be Continued.................
Please leave the comments... and give feedbacks...
No comments:
Post a Comment