
When we create a function under class then this function called method but when we create method without create class it called function. A function basically called block of code. Every function return at a time one value. We can pass the parameter by the over load the function. In the JavaScript when we write the function, we use the function keyword. Function can be non-return type means this function can’t return anything. Now given bellow the function code and explain the code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
//define the function. non-return type function
function printString(){
console.log("My name is jesy");
}
//call the function
printString();
//define the function. return type function
function printAdd(){
var a=5;
var b=6;
var c=a+b;
return c;
}
//call the function
var result=printAdd();
//print the result.
console.log("Add value: "+result);
//define the function. return type function also overloaded function.
function printAddOverload(x,y){
return x+y;
}
//call the function
var z=printAddOverload(15,10);
console.log("Add value: "+z);
</script>
</body>
</html>
In this part we write three function one is non-return type and also return type and overloaded function. When we write the JavaScript function then we use the function keyword.