CodesJava

Easy learning with example program codes

javascript function tutorial


A javascript function is a group of statements which is used for performing a specific task. We can invoke it from anywhere in our program. It provides the facility of code re-usability.

Syntax:

function functionname(parameterList) {
         //Block of statements
      }

JavaScript function example:

<html>
 <head>
 <script type="text/javascript">
 function sayHello(){
 alert("Hello codesjava.com");
 } 
 </script>
 </head> 
 <body> 
 <p>Hello World Javascript Example.</p>
 <form> 
 <input type="button" value="Say Hello" onclick="sayHello()"/> 
 </form> 
 </body> 
 </html>

Try it:

JS Bin on jsbin.com
 

JavaScript function with arguments example:

<html>
 <head>
 <script type="text/javascript">
 function sayHello(msg){
 alert(msg);
 } 
 </script>
 </head> 
 <body> 
 <p>Hello World Javascript Example.</p>
 <form> 
 <input type="button" value="Say Hello" 
     onclick="sayHello('Hello codesjava.com')"/> 
 </form> 
 </body> 
 </html>

Try it:

JS Bin on jsbin.com
 

JavaScript function return value example:

<html>
 <head>
 <script type="text/javascript">
 function sayHello(msg){
 alert(getMsg());
 } 
function getMsg(){
return "Hello codesjava.com";
 }
 </script>
 </head> 
 <body> 
 <p>Hello World Javascript Example.</p>
 <form> 
 <input type="button" value="Say Hello" onclick="sayHello()"/> 
 </form> 
 </body> 
 </html>

Try it:

JS Bin on jsbin.com
 



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki