JavaScript Functions

Like all other languages the JavaScript also supports Functions. A function is a self contained block, that have a specific code for handling. The functions always reduces to a single value. A function may have return value or may not have return value depending upon the requirement.


                   A function is executed by an event or by a call to the function.To keep the browser code that will be executed by an event or a call to the function. You may call a function from anywhere with in the page.

         Functions can be defined both in the and in the section of a document. However, to assure that a function is read/loaded by the browser before it is called, it cloud be wise to put functions in section.


 How to Define a function in JavaScript

                                                 The function definition is  similar to all other languages and in JavaScript we can define a functions like

           
         function function-name(parameter list)
         {
            // function body
         }

          Here parameter list can contain more than one and those are separated by comma(,).

For example

<html>

<head>

<script type= "text/javascript">

function display()

{

alert(" function is in head section");

}

</script>

</head>

<body>

<from>

<input type="button" value=clcikme" onClick="display()"/>

</form>

</body>

</html>

  


The output of the above program is as follows


No comments: