Home  • Programming • JavaScript

How to declare javaScript method and call it?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JavaScript and function</title>
<script type="text/javascript">
  
//--add1() method defined as procedure here----//
 function add1(x,y){
   document.writeln(x+y);
 } 

//--add2() method is defined as function here----//
 function add2(x,y){
   return x+y;
 }

</script>
</head>
<body>
<script type="text/javascript">
      
   add1(3,4); // calling procedure add1()here
   
   var r=add2(4,4);  // calling function add2()  here
   
    document.writeln(r);    

</script>
</body>
</html>

Output

7 8

Comments 0


Copyright © 2024. Powered by Intellect Software Ltd