Knowledge Walls
Ammu
Hyderabad, Andhra Pradesh, India
Passcode:
Function in Examples of Javascript 1
563 Views
Definition 
A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).
Syntax 
function name(parameter1, parameter2, parameter3) {
  // code to be executed
}

Types
1,function with return values and with parameters.
2,
function with return values and with no parameters.
3,
function with no return values and with no parameters.
4,function with no return values and with parameters.
function with no return values and with no parameters.
	<!DOCTYPE html>

	    <html lang="en-US">

	        <head>

	            <meta charset="UTF-8">

	            <title>function1</title>

	        </head>

	        <body>

	            

	            <script>

	                function sum(){

	                    document.write("sum:"+(5+6));

	                }

	 

	                sum();

	            </script>

	            

	        </body>

	    </html>
Function with no return values and with parameters
	<!DOCTYPE html>

	    <html lang="en-US">

	        <head>

	            <meta charset="UTF-8">

	            <title>function1</title>

	        </head>

	        <body>

	            

	            <script>

	                function sum(p1,p2){

	                    var p3=p1+p2;

	                    document.write("sum:"+p3);

	                }

	                sum(1,2);

	            </script>

	            

	        </body>

	    </html>
Function with return values and with parameters.
	<!DOCTYPE html>

	    <html lang="en-US">

	        <head>

	            <meta charset="UTF-8">

	            <title>function1</title>

	        </head>

	        <body>

	            <script>

	                function sum(p1,p2){

	                    var p3=p1+p2;

	                    return p3;

	                    }

	                document.write("sum:"+sum(5,2));

	            </script>

	        </body>

	    </html>
Function with return values and with no parameters 
<!DOCTYPE html>
    <html lang="en-US">
        <head>
            <meta charset="UTF-8">
            <title>function1</title>
        </head>
        <body>
            
            <script>
                function sum(){
                    var p1=10;p2=20;
                    var p3=p1+p2;
                    return p3;
                    
                }
 
                document.write("sum:"+sum());
            </script>
            
        </body>
    </html>
Next Topics
Next lessons of current book.
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
Previous Topics
Previous lessons of current book.
Examples of Javascript 1
Examples of Javascript 1
Best Lessons of "Javascript 1"
Top lessons which are viewed more times.
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details