We can create function in Java Script to perform some specific task when needed. We can use function in java script to keep some scripts inside it and is used to perform an action on the click event of any object. We can use function keyword to create function in java script.

There are three types of function in java script.
  •  Parameterize Function:  Such type of function which required some value when it called by another function. The function which called this function is known as caller function.
  • Non-Parameterize Function: Such type of function which does not require any values when it is called by another function.
  • Function which returns some value:  We can create such type function which returns some value to his caller.
Syntax for creating function
function functionname(var1,var2,...,varn)
                put some code on here.
Example which demonstrate use of function in java script
<script type="text/javascript">
        function start() {
            document.write("This is start function which is called when the document is loaded in browser.<br />");
            document.write("This is non parametrize function.<br />");
            document.write("I am going to call a parametrize function which return addition of two number.<br />");
            var num1 = 45, num2 = 66;
            var res = getAddition(num1, num2);
            document.write("Addition of two number is  : " + res + " <br />");
        function getAddition(x , y) {
            document.write("A parametrize function is called. This method will return addition of two number.<br />");
            return (x+y);
Output of the following code snippet is as follows

Function in Java Script

  Modified On Mar-22-2018 07:08:27 AM

Leave Comment