CHAPTER - 11




A function is a piece of code that can be called anywhere in the program.

The function lies idle until it is referenced or called upon to do its work.
Functions are time savers because the same piece of code you do not have to write again and again.

There are three types of functions

1. Function without parameters / Argument
2. Functions with parameters
3. Function with return value


1. Example :

<script>

function callme(){
alert("I am being called from function");
}

</script>

<input type="button" name="Submit" value="Submit" onclick="callme();">

2. Example :

<script>

function add(a,b){
//alert("I am being called from function");
document.write(a+b);
}

</script>
<input type="button" name="Submit" value="Submit" onclick="add(30,20);">

3. Example :

<!DOCTYPE html>

<html>
<body>
<p id="demo"></p>
<script>
function myFunction(a,b)
{
return a*b;
}
document.getElementById("demo").innerHTML=myFunction(4,3);
</script>
</body>
</html>

Comments

Popular posts from this blog

CHAPTER - 14

CHAPTER - 18